diff options
author | Luca Casonato <hello@lcas.dev> | 2024-07-05 10:10:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-05 10:10:22 +0200 |
commit | 08e5606c3400d3a993c0ce6748901c56fc3db35b (patch) | |
tree | 032d3a09c6d22763ceb703e7908ca159d3d7a809 /ext/node/polyfills/internal/crypto/hkdf.ts | |
parent | b290fd01f3f5d32f9d010fc719ced0240759c049 (diff) |
fix(ext/node): rewrite digest handling (#24392)
Previously we had many different code paths all
handling digests in different places, all with
wildly different digest support. This commit
rewrites this to use a single digest handling
mechanism for all digest operations.
It adds various aliases for digest algorithms,
like node does. For example
`sha1WithRSAEncryption` is an alias for `sha1`.
It also adds support for `md5-sha1` digests in
various places.
Diffstat (limited to 'ext/node/polyfills/internal/crypto/hkdf.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/hkdf.ts | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ext/node/polyfills/internal/crypto/hkdf.ts b/ext/node/polyfills/internal/crypto/hkdf.ts index 0a8dcbb2e..cca40a3c6 100644 --- a/ext/node/polyfills/internal/crypto/hkdf.ts +++ b/ext/node/polyfills/internal/crypto/hkdf.ts @@ -23,6 +23,7 @@ import { } from "ext:deno_node/internal/crypto/util.ts"; import { createSecretKey, + getKeyMaterial, isKeyObject, KeyObject, } from "ext:deno_node/internal/crypto/keys.ts"; @@ -35,7 +36,7 @@ import { const validateParameters = hideStackFrames((hash, key, salt, info, length) => { validateString(hash, "digest"); - key = new Uint8Array(prepareKey(key)); + key = getKeyMaterial(prepareKey(key)); validateByteSource(salt, "salt"); validateByteSource(info, "info"); @@ -108,6 +109,8 @@ export function hkdf( validateFunction(callback, "callback"); + hash = hash.toLowerCase(); + op_node_hkdf_async(hash, key, salt, info, length) .then((okm) => callback(null, okm.buffer)) .catch((err) => callback(new ERR_CRYPTO_INVALID_DIGEST(err), undefined)); @@ -128,6 +131,8 @@ export function hkdfSync( length, )); + hash = hash.toLowerCase(); + const okm = new Uint8Array(length); try { op_node_hkdf(hash, key, salt, info, okm); |