From aae3a6bcb41fdb305d61a95f176be0db1513c56e Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 11 Sep 2024 19:24:17 +0900 Subject: fix(ext/node): fix `Cipheriv#update(string, undefined)` (#25571) --- tests/unit_node/crypto/crypto_cipher_test.ts | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'tests/unit_node') diff --git a/tests/unit_node/crypto/crypto_cipher_test.ts b/tests/unit_node/crypto/crypto_cipher_test.ts index ad424e5d4..20b9d052f 100644 --- a/tests/unit_node/crypto/crypto_cipher_test.ts +++ b/tests/unit_node/crypto/crypto_cipher_test.ts @@ -139,16 +139,32 @@ Deno.test({ Deno.test({ name: "createCipheriv - input encoding", fn() { - const cipher = crypto.createCipheriv( - "aes-128-cbc", - new Uint8Array(16), - new Uint8Array(16), - ); - assertEquals( - cipher.update("hello, world! hello, world!", "utf-8", "hex"), - "ca7df4d74f51b77a7440ead38343ab0f", - ); - assertEquals(cipher.final("hex"), "d0da733dec1fa61125c80a6f97e6166e"); + { + const cipher = crypto.createCipheriv( + "aes-128-cbc", + new Uint8Array(16), + new Uint8Array(16), + ); + assertEquals( + cipher.update("hello, world! hello, world!", "utf-8", "hex"), + "ca7df4d74f51b77a7440ead38343ab0f", + ); + assertEquals(cipher.final("hex"), "d0da733dec1fa61125c80a6f97e6166e"); + } + + { + const cipher = crypto.createCipheriv( + "aes-128-cbc", + new Uint8Array(16), + new Uint8Array(16), + ); + // update with string without input encoding + assertEquals( + cipher.update("hello, world! hello, world!").toString("hex"), + "ca7df4d74f51b77a7440ead38343ab0f", + ); + assertEquals(cipher.final("hex"), "d0da733dec1fa61125c80a6f97e6166e"); + } }, }); -- cgit v1.2.3