From 3d75fb2be758772ab9d538ef40243e8317878e84 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 24 Mar 2023 22:29:14 +0900 Subject: fix(ext/node): make cipher/decipher transform stream (#18408) --- cli/tests/unit_node/crypto_cipher_test.ts | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit_node/crypto_cipher_test.ts b/cli/tests/unit_node/crypto_cipher_test.ts index b14d149f5..3f740f40c 100644 --- a/cli/tests/unit_node/crypto_cipher_test.ts +++ b/cli/tests/unit_node/crypto_cipher_test.ts @@ -1,6 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import crypto from "node:crypto"; import { Buffer } from "node:buffer"; +import { Readable } from "node:stream"; +import { buffer, text } from "node:stream/consumers"; import { assertEquals, assertThrows, @@ -89,6 +91,27 @@ Deno.test({ }, }); +Deno.test({ + name: "createCipheriv - transform stream", + async fn() { + const result = await buffer( + Readable.from("foo".repeat(15)).pipe(crypto.createCipheriv( + "aes-128-cbc", + new Uint8Array(16), + new Uint8Array(16), + )), + ); + // deno-fmt-ignore + assertEquals([...result], [ + 129, 19, 202, 142, 137, 51, 23, 53, 198, 33, + 214, 125, 17, 5, 128, 57, 162, 217, 220, 53, + 172, 51, 85, 113, 71, 250, 44, 156, 80, 4, + 158, 92, 185, 173, 67, 47, 255, 71, 78, 187, + 80, 206, 42, 5, 34, 104, 1, 54 + ]); + }, +}); + Deno.test({ name: "createDecipheriv - basic", fn() { @@ -110,3 +133,24 @@ Deno.test({ ); }, }); + +Deno.test({ + name: "createDecipheriv - transform stream", + async fn() { + const stream = Readable.from([ + // deno-fmt-ignore + new Uint8Array([ + 129, 19, 202, 142, 137, 51, 23, 53, 198, 33, + 214, 125, 17, 5, 128, 57, 162, 217, 220, 53, + 172, 51, 85, 113, 71, 250, 44, 156, 80, 4, + 158, 92, 185, 173, 67, 47, 255, 71, 78, 187, + 80, 206, 42, 5, 34, 104, 1, 54 + ]), + ]).pipe(crypto.createDecipheriv( + "aes-128-cbc", + new Uint8Array(16), + new Uint8Array(16), + )); + assertEquals(await text(stream), "foo".repeat(15)); + }, +}); -- cgit v1.2.3