Fix AttachmentCipherTest

This commit is contained in:
Nicholas Tinsley 2023-09-05 13:20:19 -04:00
parent e9777ccfc6
commit b5afc1cd1c
2 changed files with 7 additions and 7 deletions

View file

@ -33,7 +33,7 @@ class AttachmentCipherOutputStreamFactory(private val key: ByteArray, private va
}
val privateKey = key.sliceArray(AES_KEY_LENGTH until key.size)
val chunkSizeChoice = ChunkSizeChoice.inferChunkSize(length.toInt().coerceAtLeast(1))
val chunkSizeChoice = ChunkSizeChoice.inferChunkSize(length.toInt())
val incrementalStream = IncrementalMacOutputStream(wrap, privateKey, chunkSizeChoice, incrementalDigestOut)
return createFor(incrementalStream)
}

View file

@ -67,12 +67,12 @@ public final class AttachmentCipherTest {
try {
byte[] key = Util.getSecretBytes(64);
byte[] plaintextInput = "Gwen Stacy".getBytes();
EncryptResult encryptResult = encryptData(plaintextInput, key, false);
EncryptResult encryptResult = encryptData(plaintextInput, key, true);
byte[] badKey = new byte[64];
cipherFile = writeToFile(encryptResult.ciphertext);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, badKey, encryptResult.digest, encryptResult.incrementalDigest);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, badKey, encryptResult.digest, null);
} catch (InvalidMessageException e) {
hitCorrectException = true;
} finally {
@ -92,12 +92,12 @@ public final class AttachmentCipherTest {
try {
byte[] key = Util.getSecretBytes(64);
byte[] plaintextInput = "Mary Jane Watson".getBytes();
EncryptResult encryptResult = encryptData(plaintextInput, key, false);
EncryptResult encryptResult = encryptData(plaintextInput, key, true);
byte[] badDigest = new byte[32];
cipherFile = writeToFile(encryptResult.ciphertext);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, key, badDigest, encryptResult.incrementalDigest);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, key, badDigest, null);
} catch (InvalidMessageException e) {
hitCorrectException = true;
} finally {
@ -213,14 +213,14 @@ public final class AttachmentCipherTest {
try {
byte[] key = Util.getSecretBytes(64);
byte[] plaintextInput = "Uncle Ben".getBytes();
EncryptResult encryptResult = encryptData(plaintextInput, key, false);
EncryptResult encryptResult = encryptData(plaintextInput, key, true);
byte[] badMacCiphertext = Arrays.copyOf(encryptResult.ciphertext, encryptResult.ciphertext.length);
badMacCiphertext[badMacCiphertext.length - 1] += 1;
cipherFile = writeToFile(badMacCiphertext);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, key, encryptResult.digest, encryptResult.incrementalDigest);
AttachmentCipherInputStream.createForAttachment(cipherFile, plaintextInput.length, key, encryptResult.digest, null);
fail();
} catch (InvalidMessageException e) {
hitCorrectException = true;