diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-24 19:43:26 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-24 14:13:26 +0000 |
| commit | d740a9e43dad5b3824c3ff2f4aa66cc57a1db185 (patch) | |
| tree | 2511b522f07ef949a82d3e2d39a0263a49dad9df /ext/node/polyfills/internal/crypto/hash.ts | |
| parent | 3d75fb2be758772ab9d538ef40243e8317878e84 (diff) | |
feat(ext/node): implement crypto.createSecretKey (#18413)
This commit adds the `crypto.createSecretKey` API.
Key management: This follows the same approach as our WebCrypto
CryptoKey impl where we use WeakMap for storing key material and a
handle is passed around, such that (only internal) JS can access the key
material and we don't have to explicitly close a Rust resource.
As a result, `createHmac` now accepts a secret KeyObject.
Closes https://github.com/denoland/deno/issues/17844
Diffstat (limited to 'ext/node/polyfills/internal/crypto/hash.ts')
| -rw-r--r-- | ext/node/polyfills/internal/crypto/hash.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/node/polyfills/internal/crypto/hash.ts b/ext/node/polyfills/internal/crypto/hash.ts index d81844f30..63c92190c 100644 --- a/ext/node/polyfills/internal/crypto/hash.ts +++ b/ext/node/polyfills/internal/crypto/hash.ts @@ -15,10 +15,10 @@ import type { Encoding, } from "ext:deno_node/internal/crypto/types.ts"; import { + getKeyMaterial, KeyObject, prepareSecretKey, } from "ext:deno_node/internal/crypto/keys.ts"; -import { notImplemented } from "ext:deno_node/_utils.ts"; const { ops } = globalThis.__bootstrap.core; @@ -170,12 +170,12 @@ class HmacImpl extends Transform { }); // deno-lint-ignore no-this-alias const self = this; - if (key instanceof KeyObject) { - notImplemented("Hmac: KeyObject key is not implemented"); - } validateString(hmac, "hmac"); - const u8Key = prepareSecretKey(key, options?.encoding) as Buffer; + + const u8Key = key instanceof KeyObject + ? getKeyMaterial(key) + : prepareSecretKey(key, options?.encoding) as Buffer; const alg = hmac.toLowerCase(); this.#algorithm = alg; |
