summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/crypto/cipher.ts
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-03-25 15:42:07 +0900
committerGitHub <noreply@github.com>2023-03-25 15:42:07 +0900
commit70e2e8f2dd740fcbe4c09cfc59915320b7c22be3 (patch)
treef736c8fba79eb61e148209e55386b1dc9fc54c94 /ext/node/polyfills/internal/crypto/cipher.ts
parent255b06d7936aeeda51d4c91006f14b8383cb9f37 (diff)
fix(ext/node): add aes-128-ecb algorithm support (#18412)
Diffstat (limited to 'ext/node/polyfills/internal/crypto/cipher.ts')
-rw-r--r--ext/node/polyfills/internal/crypto/cipher.ts10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/node/polyfills/internal/crypto/cipher.ts b/ext/node/polyfills/internal/crypto/cipher.ts
index 670c1bcce..050cf5904 100644
--- a/ext/node/polyfills/internal/crypto/cipher.ts
+++ b/ext/node/polyfills/internal/crypto/cipher.ts
@@ -18,7 +18,7 @@ import type {
} from "ext:deno_node/internal/crypto/types.ts";
import { getDefaultEncoding } from "ext:deno_node/internal/crypto/util.ts";
-const { ops } = globalThis.__bootstrap.core;
+const { ops, encode } = globalThis.__bootstrap.core;
export type CipherCCMTypes =
| "aes-128-ccm"
@@ -116,6 +116,10 @@ export interface DecipherOCB extends Decipher {
): this;
}
+function toU8(input: string | Uint8Array): Uint8Array {
+ return typeof input === "string" ? encode(input) : input;
+}
+
export class Cipheriv extends Transform implements Cipher {
/** CipherContext resource id */
#context: number;
@@ -141,7 +145,7 @@ export class Cipheriv extends Transform implements Cipher {
...options,
});
this.#cache = new BlockModeCache(false);
- this.#context = ops.op_node_create_cipheriv(cipher, key, iv);
+ this.#context = ops.op_node_create_cipheriv(cipher, toU8(key), toU8(iv));
}
final(encoding: string = getDefaultEncoding()): Buffer | string {
@@ -257,7 +261,7 @@ export class Decipheriv extends Transform implements Cipher {
...options,
});
this.#cache = new BlockModeCache(true);
- this.#context = ops.op_node_create_decipheriv(cipher, key, iv);
+ this.#context = ops.op_node_create_decipheriv(cipher, toU8(key), toU8(iv));
}
final(encoding: string = getDefaultEncoding()): Buffer | string {