From 3f15e300625723df10c564c4e29ec276288a931b Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 13 Sep 2024 01:13:56 +0900 Subject: 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 --- ext/node/polyfills/internal/crypto/cipher.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ext/node') diff --git a/ext/node/polyfills/internal/crypto/cipher.ts b/ext/node/polyfills/internal/crypto/cipher.ts index a1449cd87..c1c5ce890 100644 --- a/ext/node/polyfills/internal/crypto/cipher.ts +++ b/ext/node/polyfills/internal/crypto/cipher.ts @@ -306,6 +306,10 @@ class BlockModeCache { this.cache = this.cache.subarray(len); return out; } + + set lastChunkIsNonZero(value: boolean) { + this.#lastChunkIsNonZero = value; + } } export class Decipheriv extends Transform implements Cipher { @@ -338,7 +342,7 @@ export class Decipheriv extends Transform implements Cipher { }, ...options, }); - this.#cache = new BlockModeCache(true); + this.#cache = new BlockModeCache(this.#autoPadding); this.#context = op_node_create_decipheriv(cipher, toU8(key), toU8(iv)); this.#needsBlockCache = !(cipher == "aes-128-gcm" || cipher == "aes-256-gcm"); @@ -386,6 +390,7 @@ export class Decipheriv extends Transform implements Cipher { setAutoPadding(autoPadding?: boolean): this { this.#autoPadding = Boolean(autoPadding); + this.#cache.lastChunkIsNonZero = this.#autoPadding; return this; } -- cgit v1.2.3