File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
main/java/nl/nl2312/okio/cipher
test/java/nl/nl2312/okio/cipher Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,10 @@ class CipherSource(
4343 }
4444 if (streamEnd) {
4545 // Finalize (with padding) if we are at the end
46- decipheredBuffer.write(cipher.doFinal())
46+ val remainder = cipher.doFinal()
47+ if (remainder != null ) {
48+ decipheredBuffer.write(remainder)
49+ }
4750 }
4851
4952 // Sink the requested number of bytes (or all that were still in the source)
Original file line number Diff line number Diff line change @@ -35,6 +35,16 @@ class CipherSourceTest {
3535 decodeCipher.init (Cipher .DECRYPT_MODE , secretKeySpec, iv)
3636 }
3737
38+ @Test
39+ fun read_emptySource () {
40+ val cipheredSource = Buffer ()// .write(byteArrayOf())
41+
42+ val decoded = CipherSource (cipheredSource, decodeCipher)
43+
44+ val output = Buffer ().also { it.writeAll(decoded) }
45+ assertThat(output.readUtf8()).isEqualTo(" " )
46+ }
47+
3848 @Test
3949 fun read_cipheredArray_oneBlock () {
4050 // NOTE Input is shorter than 1 cipher block of 16 bytes
You can’t perform that action at this time.
0 commit comments