diff --git a/lib/internal/crypto/aes.js b/lib/internal/crypto/aes.js index 76b3b90b753e68..98fa776c0ff137 100644 --- a/lib/internal/crypto/aes.js +++ b/lib/internal/crypto/aes.js @@ -223,7 +223,7 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) { const usageSet = new SafeSet(keyUsages); - if (hasAnyNotIn(usageSet, 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey')) { + if (hasAnyNotIn(usageSet, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])) { throw lazyDOMException( 'Unsupported key usage for an AES key', 'SyntaxError'); @@ -258,7 +258,8 @@ async function aesImportKey( if (name !== 'AES-KW') ArrayPrototypePush(checkUsages, 'encrypt', 'decrypt'); - if (ReflectApply(hasAnyNotIn, null, checkUsages)) { + const usagesSet = new SafeSet(keyUsages); + if (hasAnyNotIn(usagesSet, checkUsages)) { throw lazyDOMException( 'Unsupported key usage for an AES key', 'SyntaxError'); diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index a23974a531e402..a3c2fb5db55c2c 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -357,7 +357,7 @@ function verifyAcceptableDhKeyUse(name, type, usages) { case 'public': break; } - if (ReflectApply(hasAnyNotIn, null, args)) { + if (hasAnyNotIn(usages, checkSet)) { throw lazyDOMException( `Unsupported key usage for an ${name} key`, 'SyntaxError'); @@ -370,7 +370,7 @@ async function dhGenerateKey( keyUsages) { const usageSet = new SafeSet(keyUsages); - if (hasAnyNotIn(usageSet, 'deriveKey', 'deriveBits')) { + if (hasAnyNotIn(usageSet, ['deriveKey', 'deriveBits'])) { throw lazyDOMException( 'Unsupported key usage for a DH key', 'SyntaxError'); diff --git a/lib/internal/crypto/dsa.js b/lib/internal/crypto/dsa.js index 17a255fa77727c..fd1f3652e698eb 100644 --- a/lib/internal/crypto/dsa.js +++ b/lib/internal/crypto/dsa.js @@ -60,7 +60,7 @@ function verifyAcceptableDsaKeyUse(name, type, usages) { check = 'verify'; break; } - if (hasAnyNotIn(usages, check)) { + if (hasAnyNotIn(usages, checkSet)) { throw lazyDOMException( `Unsupported key usage for an ${name} key`, 'SyntaxError'); @@ -84,7 +84,7 @@ async function dsaGenerateKey( const usageSet = new SafeSet(keyUsages); - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { throw lazyDOMException( 'Unsupported key usage for a DSA key', 'SyntaxError'); diff --git a/lib/internal/crypto/ec.js b/lib/internal/crypto/ec.js index 68ef854d7eb4f8..2231366d33f09a 100644 --- a/lib/internal/crypto/ec.js +++ b/lib/internal/crypto/ec.js @@ -80,7 +80,7 @@ function verifyAcceptableEcKeyUse(name, type, usages) { break; } } - if (ReflectApply(hasAnyNotIn, null, args)) { + if (hasAnyNotIn(usages, checkSet)) { throw lazyDOMException( `Unsupported key usage for a ${name} key`, 'SyntaxError'); @@ -150,14 +150,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { case 'NODE-ED25519': // Fall through case 'NODE-ED448': - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { throw lazyDOMException( 'Unsupported key usage for an ECDSA key', 'SyntaxError'); } break; case 'ECDH': - if (hasAnyNotIn(usageSet, 'deriveKey', 'deriveBits')) { + if (hasAnyNotIn(usageSet, ['deriveKey', 'deriveBits'])) { throw lazyDOMException( 'Unsupported key usage for an ECDH key', 'SyntaxError'); diff --git a/lib/internal/crypto/mac.js b/lib/internal/crypto/mac.js index af6b95340f73bd..5ee1f0918db7e1 100644 --- a/lib/internal/crypto/mac.js +++ b/lib/internal/crypto/mac.js @@ -56,7 +56,7 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) { validateBitLength(length, 'algorithm.length', true); const usageSet = new SafeSet(keyUsages); - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { throw lazyDOMException( 'Unsupported key usage for an HMAC key', 'SyntaxError'); @@ -89,7 +89,7 @@ async function hmacImportKey( throw new ERR_MISSING_OPTION('algorithm.hash'); const usagesSet = new SafeSet(keyUsages); - if (hasAnyNotIn(usagesSet, 'sign', 'verify')) { + if (hasAnyNotIn(usagesSet, ['sign', 'verify'])) { throw lazyDOMException( 'Unsupported key usage for an HMAC key', 'SyntaxError'); diff --git a/lib/internal/crypto/rsa.js b/lib/internal/crypto/rsa.js index 809747ea011373..1e0ea3f6e74d3b 100644 --- a/lib/internal/crypto/rsa.js +++ b/lib/internal/crypto/rsa.js @@ -95,7 +95,7 @@ function verifyAcceptableRsaKeyUse(name, type, usages) { break; } } - if (ReflectApply(hasAnyNotIn, null, args)) { + if (hasAnyNotIn(usages, checkSet)) { throw lazyDOMException( `Unsupported key usage for an ${name} key`, 'SyntaxError'); @@ -157,14 +157,15 @@ async function rsaKeyGenerate( switch (name) { case 'RSA-OAEP': - if (hasAnyNotIn(usageSet, 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey')) { + if (hasAnyNotIn(usageSet, + ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])) { throw lazyDOMException( 'Unsupported key usage for a RSA key', 'SyntaxError'); } break; default: - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { throw lazyDOMException( 'Unsupported key usage for a RSA key', 'SyntaxError'); diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index c580ce2571e03e..a717e661a30fee 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -236,7 +236,7 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') { throw lazyDOMException('Unrecognized name.', 'NotSupportedError'); } -function hasAnyNotIn(set, ...check) { +function hasAnyNotIn(set, check) { for (const s of set) if (!ArrayPrototypeIncludes(check, s)) return true; diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index eba0b08e836c38..57e3ee3af11eb2 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -402,7 +402,7 @@ async function importGenericSecretKey( if (extractable) throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError'); - if (hasAnyNotIn(usagesSet, 'deriveKey', 'deriveBits')) { + if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) { throw lazyDOMException( `Unsupported key usage for a ${name} key`, 'SyntaxError'); @@ -419,7 +419,7 @@ async function importGenericSecretKey( break; } case 'raw': - if (hasAnyNotIn(usagesSet, 'deriveKey', 'deriveBits')) { + if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) { throw lazyDOMException( `Unsupported key usage for a ${name} key`, 'SyntaxError');