diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-09-13 01:13:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 01:13:56 +0900 |
commit | 3f15e300625723df10c564c4e29ec276288a931b (patch) | |
tree | 1d0a205dc858f3dbcc3bd032d7ecbdddd414ddc4 /tests/unit_node | |
parent | 0a4a8c730bcad32dcb7c8174e33601d777e54909 (diff) |
fix(ext/node): fix Decipheriv when autoPadding disabled (#25598)
This change fixes Decipheriv behavior when autoPadding disabled and enabled.
By this change, the example given in
https://github.com/denoland/deno/issues/20924#issuecomment-2345931295
works in the same way as Node.
closes #20924
Diffstat (limited to 'tests/unit_node')
-rw-r--r-- | tests/unit_node/crypto/crypto_cipher_test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_cipher_test.ts b/tests/unit_node/crypto/crypto_cipher_test.ts index 20b9d052f..65a5b29ee 100644 --- a/tests/unit_node/crypto/crypto_cipher_test.ts +++ b/tests/unit_node/crypto/crypto_cipher_test.ts @@ -378,3 +378,41 @@ Deno.test({ assertEquals(info2.ivLength, 16); }, }); + +Deno.test({ + name: + "createDecipheriv - handling of the last chunk when auto padding enabled/disabled", + fn() { + const algorithm = "aes-256-cbc"; + const key = Buffer.from( + "84dcdd964968734fdf0de4a2cba471c2e0a753930b841c014b1e77f456b5797b", + "hex", + ); + const val = Buffer.from( + "feabbdf66e2c71cc780d0cd2765dcce283e8ae7e58fcc1a9acafc678581e0e06", + "hex", + ); + const iv = Buffer.alloc(16, 0); + + { + const decipher = crypto.createDecipheriv(algorithm, key, iv); + decipher.setAutoPadding(false); + assertEquals( + decipher.update(val, undefined, "hex"), + "ed2c908f26571bf8e50d60b77fb9c25f95b933b59111543c6fac41ad6b47e681", + ); + assertEquals(decipher.final("hex"), ""); + } + + { + const decipher = crypto.createDecipheriv(algorithm, key, iv); + assertEquals( + decipher.update(val, undefined, "hex"), + "ed2c908f26571bf8e50d60b77fb9c25f", + ); + assertThrows(() => { + decipher.final(); + }); + } + }, +}); |