Rename TruncatingInputStream -> LimitedInputStream.

This commit is contained in:
Greyson Parrelli
2024-09-06 08:13:50 -04:00
committed by Cody Henthorne
parent a6767e4f8a
commit a8fb4eb21a
7 changed files with 55 additions and 47 deletions

View File

@@ -9,8 +9,8 @@ import com.google.common.io.CountingInputStream
import org.signal.core.util.readFully
import org.signal.core.util.readNBytesOrThrow
import org.signal.core.util.readVarInt32
import org.signal.core.util.stream.LimitedInputStream
import org.signal.core.util.stream.MacInputStream
import org.signal.core.util.stream.TruncatingInputStream
import org.thoughtcrime.securesms.backup.v2.proto.BackupInfo
import org.thoughtcrime.securesms.backup.v2.proto.Frame
import org.whispersystems.signalservice.api.backup.BackupKey
@@ -56,7 +56,7 @@ class EncryptedBackupReader(
stream = GZIPInputStream(
CipherInputStream(
TruncatingInputStream(
LimitedInputStream(
wrapped = countingStream,
maxBytes = length - MAC_SIZE
),
@@ -121,7 +121,7 @@ class EncryptedBackupReader(
}
val macStream = MacInputStream(
wrapped = TruncatingInputStream(dataStream, maxBytes = streamLength - MAC_SIZE),
wrapped = LimitedInputStream(dataStream, maxBytes = streamLength - MAC_SIZE),
mac = mac
)

View File

@@ -19,7 +19,7 @@ package org.thoughtcrime.securesms.crypto;
import androidx.annotation.NonNull;
import org.signal.core.util.logging.Log;
import org.signal.core.util.stream.TruncatingInputStream;
import org.signal.core.util.stream.LimitedInputStream;
import org.thoughtcrime.securesms.util.Util;
import java.io.File;
@@ -63,7 +63,7 @@ public class ClassicDecryptingPartInputStream {
IvParameterSpec iv = new IvParameterSpec(ivBytes);
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(attachmentSecret.getClassicCipherKey(), "AES"), iv);
return new CipherInputStreamWrapper(new TruncatingInputStream(fileStream, file.length() - MAC_LENGTH - IV_LENGTH), cipher);
return new CipherInputStreamWrapper(new LimitedInputStream(fileStream, file.length() - MAC_LENGTH - IV_LENGTH), cipher);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) {
throw new AssertionError(e);
}
@@ -72,7 +72,7 @@ public class ClassicDecryptingPartInputStream {
private static void verifyMac(AttachmentSecret attachmentSecret, File file) throws IOException {
Mac mac = initializeMac(new SecretKeySpec(attachmentSecret.getClassicMacKey(), "HmacSHA1"));
FileInputStream macStream = new FileInputStream(file);
InputStream dataStream = new TruncatingInputStream(new FileInputStream(file), file.length() - MAC_LENGTH);
InputStream dataStream = new LimitedInputStream(new FileInputStream(file), file.length() - MAC_LENGTH);
byte[] theirMac = new byte[MAC_LENGTH];
if (macStream.skip(file.length() - MAC_LENGTH) != file.length() - MAC_LENGTH) {