Skip to content

Commit

Permalink
allow encrypting empty chunks
Browse files Browse the repository at this point in the history
related to f07ef0e
  • Loading branch information
overheadhunter committed Jan 10, 2025
1 parent 084e78a commit 2445d1c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ByteBuffer encryptChunk(ByteBuffer cleartextChunk, long chunkNumber, File

@Override
public void encryptChunk(ByteBuffer cleartextChunk, ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header) {
if (cleartextChunk.remaining() <= 0 || cleartextChunk.remaining() > PAYLOAD_SIZE) {
if (cleartextChunk.remaining() < 0 || cleartextChunk.remaining() > PAYLOAD_SIZE) {
throw new IllegalArgumentException("Invalid cleartext chunk size: " + cleartextChunk.remaining() + ", expected range [1, " + PAYLOAD_SIZE + "]");
}
if (ciphertextChunk.remaining() < CHUNK_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class Encryption {

@DisplayName("encrypt chunk with invalid size")
@ParameterizedTest(name = "cleartext size: {0}")
@ValueSource(ints = {0, org.cryptomator.cryptolib.v2.Constants.PAYLOAD_SIZE + 1})
@ValueSource(ints = {0, Constants.PAYLOAD_SIZE + 1})
public void testEncryptChunkOfInvalidSize(int size) {
ByteBuffer cleartext = ByteBuffer.allocate(size);

Expand Down Expand Up @@ -147,7 +147,7 @@ public class Decryption {

@DisplayName("decrypt chunk with invalid size")
@ParameterizedTest(name = "ciphertext size: {0}")
@ValueSource(ints = {0, Constants.GCM_NONCE_SIZE + Constants.GCM_TAG_SIZE - 1, org.cryptomator.cryptolib.v2.Constants.CHUNK_SIZE + 1})
@ValueSource(ints = {0, Constants.GCM_NONCE_SIZE + Constants.GCM_TAG_SIZE - 1, Constants.CHUNK_SIZE + 1})
public void testDecryptChunkOfInvalidSize(int size) {
ByteBuffer ciphertext = ByteBuffer.allocate(size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class Encryption {

@DisplayName("encrypt chunk with invalid size")
@ParameterizedTest(name = "cleartext size: {0}")
@ValueSource(ints = {0, Constants.PAYLOAD_SIZE + 1})
@ValueSource(ints = {Constants.PAYLOAD_SIZE + 1})
public void testEncryptChunkOfInvalidSize(int size) {
ByteBuffer cleartext = ByteBuffer.allocate(size);

Expand Down

0 comments on commit 2445d1c

Please sign in to comment.