Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFilip Skokan <panva.ip@gmail.com>2022-04-03 13:11:21 +0300
committerGitHub <noreply@github.com>2022-04-03 13:11:21 +0300
commit5d0eb10c80843badca677b82995c8decd401b08e (patch)
treeba08e799eca235e1083fa2bee24d3c6aed839f5a /lib
parente12cfd85aee61295ce8517d86c0ec3cd7c0ecd9a (diff)
crypto: do not add undefined hash in webcrypto normalizeAlgorithm
PR-URL: https://github.com/nodejs/node/pull/42559 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/crypto/util.js15
-rw-r--r--lib/internal/crypto/webcrypto.js4
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js
index eafcc3d9669..9492409e3a6 100644
--- a/lib/internal/crypto/util.js
+++ b/lib/internal/crypto/util.js
@@ -206,30 +206,33 @@ function validateMaxBufferLength(data, name) {
}
}
-function normalizeAlgorithm(algorithm, label = 'algorithm') {
+function normalizeAlgorithm(algorithm) {
if (algorithm != null) {
if (typeof algorithm === 'string')
algorithm = { name: algorithm };
if (typeof algorithm === 'object') {
const { name } = algorithm;
- let hash;
if (typeof name !== 'string' ||
!ArrayPrototypeIncludes(
kAlgorithmsKeys,
StringPrototypeToLowerCase(name))) {
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
}
- if (algorithm.hash !== undefined) {
- hash = normalizeAlgorithm(algorithm.hash, 'algorithm.hash');
+ let { hash } = algorithm;
+ if (hash !== undefined) {
+ hash = normalizeAlgorithm(hash);
if (!ArrayPrototypeIncludes(kHashTypes, hash.name))
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
}
- return {
+ const normalized = {
...algorithm,
name: kAlgorithms[StringPrototypeToLowerCase(name)],
- hash,
};
+ if (hash) {
+ normalized.hash = hash;
+ }
+ return normalized;
}
}
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js
index e9380ed53bf..cf440ebf8ff 100644
--- a/lib/internal/crypto/webcrypto.js
+++ b/lib/internal/crypto/webcrypto.js
@@ -587,10 +587,10 @@ async function unwrapKey(
extractable,
keyUsages) {
wrappedKey = getArrayBufferOrView(wrappedKey, 'wrappedKey');
-
+ unwrapAlgo = normalizeAlgorithm(unwrapAlgo);
let keyData = await cipherOrWrap(
kWebCryptoCipherDecrypt,
- normalizeAlgorithm(unwrapAlgo),
+ unwrapAlgo,
unwrappingKey,
wrappedKey,
'unwrapKey');