| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c0cdb83 commit b1e188d
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ const { | |||
| 8 | 8 | ArrayPrototypePush, | |
| 9 | 9 | MathFloor, | |
| 10 | 10 | Promise, | |
| 11 | - ReflectApply, | ||
| 12 | 11 | SafeSet, | |
| 13 | 12 | TypedArrayPrototypeSlice, | |
| 14 | 13 | } = primordials; | |
@@ -223,7 +222,7 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) { | |||
| 223 | 222 | ||
| 224 | 223 | const usageSet = new SafeSet(keyUsages); | |
| 225 | 224 | ||
| 226 | - if (hasAnyNotIn(usageSet, 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey')) { | ||
| 225 | + if (hasAnyNotIn(usageSet, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])) { | ||
| 227 | 226 | throw lazyDOMException( | |
| 228 | 227 | 'Unsupported key usage for an AES key', | |
| 229 | 228 | 'SyntaxError'); | |
@@ -253,12 +252,12 @@ async function aesImportKey( | |||
| 253 | 252 | extractable, | |
| 254 | 253 | keyUsages) { | |
| 255 | 254 | const { name } = algorithm; | |
| 256 | - const usagesSet = new SafeSet(keyUsages); | ||
| 257 | - const checkUsages = [usagesSet, 'wrapKey', 'unwrapKey']; | ||
| 255 | + const checkUsages = ['wrapKey', 'unwrapKey']; | ||
| 258 | 256 | if (name !== 'AES-KW') | |
| 259 | 257 | ArrayPrototypePush(checkUsages, 'encrypt', 'decrypt'); | |
| 260 | 258 | ||
| 261 | - if (ReflectApply(hasAnyNotIn, null, checkUsages)) { | ||
| 259 | + const usagesSet = new SafeSet(keyUsages); | ||
| 260 | + if (hasAnyNotIn(usagesSet, checkUsages)) { | ||
| 262 | 261 | throw lazyDOMException( | |
| 263 | 262 | 'Unsupported key usage for an AES key', | |
| 264 | 263 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,12 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ArrayBufferPrototypeSlice, | |
| 5 | - ArrayPrototypePush, | ||
| 6 | 5 | FunctionPrototypeCall, | |
| 7 | 6 | MathFloor, | |
| 8 | 7 | ObjectDefineProperty, | |
| 9 | 8 | Promise, | |
| 10 | - ReflectApply, | ||
| 11 | 9 | SafeSet, | |
| 12 | 10 | } = primordials; | |
| 13 | 11 | ||
@@ -349,15 +347,16 @@ function deriveBitsDH(publicKey, privateKey, callback) { | |||
| 349 | 347 | } | |
| 350 | 348 | ||
| 351 | 349 | function verifyAcceptableDhKeyUse(name, type, usages) { | |
| 352 | - const args = [usages]; | ||
| 350 | + let checkSet; | ||
| 353 | 351 | switch (type) { | |
| 354 | 352 | case 'private': | |
| 355 | - ArrayPrototypePush(args, 'deriveBits', 'deriveKey'); | ||
| 353 | + checkSet = ['deriveBits', 'deriveKey']; | ||
| 356 | 354 | break; | |
| 357 | 355 | case 'public': | |
| 356 | + checkSet = []; | ||
| 358 | 357 | break; | |
| 359 | 358 | } | |
| 360 | - if (ReflectApply(hasAnyNotIn, null, args)) { | ||
| 359 | + if (hasAnyNotIn(usages, checkSet)) { | ||
| 361 | 360 | throw lazyDOMException( | |
| 362 | 361 | `Unsupported key usage for an ${name} key`, | |
| 363 | 362 | 'SyntaxError'); | |
@@ -370,7 +369,7 @@ async function dhGenerateKey( | |||
| 370 | 369 | keyUsages) { | |
| 371 | 370 | const usageSet = new SafeSet(keyUsages); | |
| 372 | 371 | ||
| 373 | - if (hasAnyNotIn(usageSet, 'deriveKey', 'deriveBits')) { | ||
| 372 | + if (hasAnyNotIn(usageSet, ['deriveKey', 'deriveBits'])) { | ||
| 374 | 373 | throw lazyDOMException( | |
| 375 | 374 | 'Unsupported key usage for a DH key', | |
| 376 | 375 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,16 +51,16 @@ const { | |||
| 51 | 51 | } = require('internal/crypto/util'); | |
| 52 | 52 | ||
| 53 | 53 | function verifyAcceptableDsaKeyUse(name, type, usages) { | |
| 54 | - let check; | ||
| 54 | + let checkSet; | ||
| 55 | 55 | switch (type) { | |
| 56 | 56 | case 'private': | |
| 57 | - check = 'sign'; | ||
| 57 | + checkSet = ['sign']; | ||
| 58 | 58 | break; | |
| 59 | 59 | case 'public': | |
| 60 | - check = 'verify'; | ||
| 60 | + checkSet = ['verify']; | ||
| 61 | 61 | break; | |
| 62 | 62 | } | |
| 63 | - if (hasAnyNotIn(usages, check)) { | ||
| 63 | + if (hasAnyNotIn(usages, checkSet)) { | ||
| 64 | 64 | throw lazyDOMException( | |
| 65 | 65 | `Unsupported key usage for an ${name} key`, | |
| 66 | 66 | 'SyntaxError'); | |
@@ -84,7 +84,7 @@ async function dsaGenerateKey( | |||
| 84 | 84 | ||
| 85 | 85 | const usageSet = new SafeSet(keyUsages); | |
| 86 | 86 | ||
| 87 | - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { | ||
| 87 | + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { | ||
| 88 | 88 | throw lazyDOMException( | |
| 89 | 89 | 'Unsupported key usage for a DSA key', | |
| 90 | 90 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,8 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | - ArrayPrototypePush, | ||
| 5 | 4 | ObjectKeys, | |
| 6 | 5 | Promise, | |
| 7 | - ReflectApply, | ||
| 8 | 6 | SafeSet, | |
| 9 | 7 | } = primordials; | |
| 10 | 8 | ||
@@ -61,10 +59,10 @@ const { | |||
| 61 | 59 | } = require('internal/crypto/keys'); | |
| 62 | 60 | ||
| 63 | 61 | function verifyAcceptableEcKeyUse(name, type, usages) { | |
| 64 | - const args = [usages]; | ||
| 62 | + let checkSet; | ||
| 65 | 63 | switch (name) { | |
| 66 | 64 | case 'ECDH': | |
| 67 | - ArrayPrototypePush(args, 'deriveKey', 'deriveBits'); | ||
| 65 | + checkSet = ['deriveKey', 'deriveBits']; | ||
| 68 | 66 | break; | |
| 69 | 67 | case 'NODE-ED25519': | |
| 70 | 68 | // Fall through | |
@@ -73,14 +71,14 @@ function verifyAcceptableEcKeyUse(name, type, usages) { | |||
| 73 | 71 | case 'ECDSA': | |
| 74 | 72 | switch (type) { | |
| 75 | 73 | case 'private': | |
| 76 | - ArrayPrototypePush(args, 'sign'); | ||
| 74 | + checkSet = ['sign']; | ||
| 77 | 75 | break; | |
| 78 | 76 | case 'public': | |
| 79 | - ArrayPrototypePush(args, 'verify'); | ||
| 77 | + checkSet = ['verify']; | ||
| 80 | 78 | break; | |
| 81 | 79 | } | |
| 82 | 80 | } | |
| 83 | - if (ReflectApply(hasAnyNotIn, null, args)) { | ||
| 81 | + if (hasAnyNotIn(usages, checkSet)) { | ||
| 84 | 82 | throw lazyDOMException( | |
| 85 | 83 | `Unsupported key usage for a ${name} key`, | |
| 86 | 84 | 'SyntaxError'); | |
@@ -150,14 +148,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { | |||
| 150 | 148 | case 'NODE-ED25519': | |
| 151 | 149 | // Fall through | |
| 152 | 150 | case 'NODE-ED448': | |
| 153 | - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { | ||
| 151 | + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { | ||
| 154 | 152 | throw lazyDOMException( | |
| 155 | 153 | 'Unsupported key usage for an ECDSA key', | |
| 156 | 154 | 'SyntaxError'); | |
| 157 | 155 | } | |
| 158 | 156 | break; | |
| 159 | 157 | case 'ECDH': | |
| 160 | - if (hasAnyNotIn(usageSet, 'deriveKey', 'deriveBits')) { | ||
| 158 | + if (hasAnyNotIn(usageSet, ['deriveKey', 'deriveBits'])) { | ||
| 161 | 159 | throw lazyDOMException( | |
| 162 | 160 | 'Unsupported key usage for an ECDH key', | |
| 163 | 161 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,7 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) { | |||
| 56 | 56 | validateBitLength(length, 'algorithm.length', true); | |
| 57 | 57 | ||
| 58 | 58 | const usageSet = new SafeSet(keyUsages); | |
| 59 | - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { | ||
| 59 | + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { | ||
| 60 | 60 | throw lazyDOMException( | |
| 61 | 61 | 'Unsupported key usage for an HMAC key', | |
| 62 | 62 | 'SyntaxError'); | |
@@ -89,7 +89,7 @@ async function hmacImportKey( | |||
| 89 | 89 | throw new ERR_MISSING_OPTION('algorithm.hash'); | |
| 90 | 90 | ||
| 91 | 91 | const usagesSet = new SafeSet(keyUsages); | |
| 92 | - if (hasAnyNotIn(usagesSet, 'sign', 'verify')) { | ||
| 92 | + if (hasAnyNotIn(usagesSet, ['sign', 'verify'])) { | ||
| 93 | 93 | throw lazyDOMException( | |
| 94 | 94 | 'Unsupported key usage for an HMAC key', | |
| 95 | 95 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | - ArrayPrototypePush, | ||
| 5 | 4 | Promise, | |
| 6 | - ReflectApply, | ||
| 7 | 5 | SafeSet, | |
| 8 | 6 | Uint8Array, | |
| 9 | 7 | } = primordials; | |
@@ -73,29 +71,29 @@ const kRsaVariants = { | |||
| 73 | 71 | }; | |
| 74 | 72 | ||
| 75 | 73 | function verifyAcceptableRsaKeyUse(name, type, usages) { | |
| 76 | - const args = [usages]; | ||
| 74 | + let checkSet; | ||
| 77 | 75 | switch (name) { | |
| 78 | 76 | case 'RSA-OAEP': | |
| 79 | 77 | switch (type) { | |
| 80 | 78 | case 'private': | |
| 81 | - ArrayPrototypePush(args, 'decrypt', 'unwrapKey'); | ||
| 79 | + checkSet = ['decrypt', 'unwrapKey']; | ||
| 82 | 80 | break; | |
| 83 | 81 | case 'public': | |
| 84 | - ArrayPrototypePush(args, 'encrypt', 'wrapKey'); | ||
| 82 | + checkSet = ['encrypt', 'wrapKey']; | ||
| 85 | 83 | break; | |
| 86 | 84 | } | |
| 87 | 85 | break; | |
| 88 | 86 | default: | |
| 89 | 87 | switch (type) { | |
| 90 | 88 | case 'private': | |
| 91 | - ArrayPrototypePush(args, 'sign'); | ||
| 89 | + checkSet = ['sign']; | ||
| 92 | 90 | break; | |
| 93 | 91 | case 'public': | |
| 94 | - ArrayPrototypePush(args, 'verify'); | ||
| 92 | + checkSet = ['verify']; | ||
| 95 | 93 | break; | |
| 96 | 94 | } | |
| 97 | 95 | } | |
| 98 | - if (ReflectApply(hasAnyNotIn, null, args)) { | ||
| 96 | + if (hasAnyNotIn(usages, checkSet)) { | ||
| 99 | 97 | throw lazyDOMException( | |
| 100 | 98 | `Unsupported key usage for an ${name} key`, | |
| 101 | 99 | 'SyntaxError'); | |
@@ -157,14 +155,15 @@ async function rsaKeyGenerate( | |||
| 157 | 155 | ||
| 158 | 156 | switch (name) { | |
| 159 | 157 | case 'RSA-OAEP': | |
| 160 | - if (hasAnyNotIn(usageSet, 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey')) { | ||
| 158 | + if (hasAnyNotIn(usageSet, | ||
| 159 | + ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])) { | ||
| 161 | 160 | throw lazyDOMException( | |
| 162 | 161 | 'Unsupported key usage for a RSA key', | |
| 163 | 162 | 'SyntaxError'); | |
| 164 | 163 | } | |
| 165 | 164 | break; | |
| 166 | 165 | default: | |
| 167 | - if (hasAnyNotIn(usageSet, 'sign', 'verify')) { | ||
| 166 | + if (hasAnyNotIn(usageSet, ['sign', 'verify'])) { | ||
| 168 | 167 | throw lazyDOMException( | |
| 169 | 168 | 'Unsupported key usage for a RSA key', | |
| 170 | 169 | 'SyntaxError'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,9 +236,9 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') { | |||
| 236 | 236 | throw lazyDOMException('Unrecognized name.', 'NotSupportedError'); | |
| 237 | 237 | } | |
| 238 | 238 | ||
| 239 | - function hasAnyNotIn(set, ...check) { | ||
| 239 | + function hasAnyNotIn(set, checks) { | ||
| 240 | 240 | for (const s of set) | |
| 241 | - if (!ArrayPrototypeIncludes(check, s)) | ||
| 241 | + if (!ArrayPrototypeIncludes(checks, s)) | ||
| 242 | 242 | return true; | |
| 243 | 243 | return false; | |
| 244 | 244 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -402,7 +402,7 @@ async function importGenericSecretKey( | |||
| 402 | 402 | if (extractable) | |
| 403 | 403 | throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError'); | |
| 404 | 404 | ||
| 405 | - if (hasAnyNotIn(usagesSet, 'deriveKey', 'deriveBits')) { | ||
| 405 | + if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) { | ||
| 406 | 406 | throw lazyDOMException( | |
| 407 | 407 | `Unsupported key usage for a ${name} key`, | |
| 408 | 408 | 'SyntaxError'); | |
@@ -419,7 +419,7 @@ async function importGenericSecretKey( | |||
| 419 | 419 | break; | |
| 420 | 420 | } | |
| 421 | 421 | case 'raw': | |
| 422 | - if (hasAnyNotIn(usagesSet, 'deriveKey', 'deriveBits')) { | ||
| 422 | + if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) { | ||
| 423 | 423 | throw lazyDOMException( | |
| 424 | 424 | `Unsupported key usage for a ${name} key`, | |
| 425 | 425 | 'SyntaxError'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments