mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
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>
This commit is contained in:
1 parent
e12cfd85ae
commit
5d0eb10c80
3 files changed
+36
-8
No files matched your search
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user