Skip to content

Commit b5afc4a

Browse files
committed
Fix output size for JDK
1 parent e4f78a1 commit b5afc4a

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

cryptography-providers-tests/src/commonMain/kotlin/default/AesGcmTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract class AesGcmTest(provider: CryptographyProvider) : AesBasedTest<AES.GCM
6161
val key = algorithm.keyGenerator(keySize).generateKey()
6262
listOf(96, 104, 112, 120, 128).forEach { tagSizeBits ->
6363
val cipher = key.cipher(tagSizeBits.bits)
64-
repeat(10) {
64+
repeat(100) {
6565
val size = CryptographyRandom.nextInt(20000)
6666
val data = ByteString(CryptographyRandom.nextBytes(size))
6767
assertCipherViaFunction(cipher, cipher, data)
@@ -76,7 +76,7 @@ abstract class AesGcmTest(provider: CryptographyProvider) : AesBasedTest<AES.GCM
7676
val key = algorithm.keyGenerator(keySize).generateKey()
7777
listOf(96, 104, 112, 120, 128).forEach { tagSizeBits ->
7878
val cipher = key.cipher(tagSizeBits.bits)
79-
repeat(10) {
79+
repeat(100) {
8080
val size = CryptographyRandom.nextInt(20000)
8181
val data = ByteString(CryptographyRandom.nextBytes(size))
8282
assertCipherWithIvViaFunction(cipher, cipher, ivSize, data)

cryptography-providers/base/src/commonMain/kotlin/operations/BaseCipherFunction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public abstract class BaseCipherFunction : CipherFunction, AutoCloseable {
125125
}
126126

127127
// can't estimate size to fit for safe output size
128-
if (inputSize == -1 || outputSize == -1) {
128+
if (inputSize == -1 || outputSize == -1 || outputSize == 0) {
129129
outputBuffer.write(transformToByteArray(input, inputStartIndex, inputStartIndex + maxInputSize))
130130
maxInputSize
131131
} else {

cryptography-providers/jdk/src/jvmMain/kotlin/operations/JdkCipherFunction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ internal open class JdkCipherFunction(
2424

2525
val cipher = cipher.access()
2626

27+
// java Cipher can return `null` when it produces nothing
2728
return cipher.update(
2829
/* input = */ source,
2930
/* inputOffset = */ startIndex,
3031
/* inputLen = */ endIndex - startIndex
31-
)
32+
) ?: EmptyByteArray
3233
}
3334

3435
override fun transformIntoByteArray(

0 commit comments

Comments
 (0)