| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,35 +206,39 @@ function validateMaxBufferLength(data, name) { | |||
| 206 | 206 | } | |
| 207 | 207 | } | |
| 208 | 208 | ||
| 209 | - function normalizeAlgorithm(algorithm, label = 'algorithm') { | ||
| 209 | + function normalizeAlgorithm(algorithm) { | ||
| 210 | 210 | if (algorithm != null) { | |
| 211 | 211 | if (typeof algorithm === 'string') | |
| 212 | 212 | algorithm = { name: algorithm }; | |
| 213 | 213 | ||
| 214 | 214 | if (typeof algorithm === 'object') { | |
| 215 | 215 | const { name } = algorithm; | |
| 216 | - let hash; | ||
| 217 | 216 | if (typeof name !== 'string' || | |
| 218 | 217 | !ArrayPrototypeIncludes( | |
| 219 | 218 | kAlgorithmsKeys, | |
| 220 | 219 | StringPrototypeToLowerCase(name))) { | |
| 221 | 220 | throw lazyDOMException('Unrecognized name.', 'NotSupportedError'); | |
| 222 | 221 | } | |
| 223 | - if (algorithm.hash !== undefined) { | ||
| 224 | - hash = normalizeAlgorithm(algorithm.hash, 'algorithm.hash'); | ||
| 222 | + let { hash } = algorithm; | ||
| 223 | + if (hash !== undefined) { | ||
| 224 | + hash = normalizeAlgorithm(hash); | ||
| 225 | 225 | if (!ArrayPrototypeIncludes(kHashTypes, hash.name)) | |
| 226 | 226 | throw lazyDOMException('Unrecognized name.', 'NotSupportedError'); | |
| 227 | 227 | } | |
| 228 | - return { | ||
| 228 | + const normalized = { | ||
| 229 | 229 | ...algorithm, | |
| 230 | 230 | name: kAlgorithms[StringPrototypeToLowerCase(name)], | |
| 231 | - hash, | ||
| 232 | 231 | }; | |
| 232 | + if (hash) { | ||
| 233 | + normalized.hash = hash; | ||
| 234 | + } | ||
| 235 | + return normalized; | ||
| 233 | 236 | } | |
| 234 | 237 | } | |
| 235 | 238 | throw lazyDOMException('Unrecognized name.', 'NotSupportedError'); | |
| 236 | 239 | } | |
| 237 | 240 | ||
| 241 | + | ||
| 238 | 242 | function hasAnyNotIn(set, checks) { | |
| 239 | 243 | for (const s of set) | |
| 240 | 244 | if (!ArrayPrototypeIncludes(checks, s)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -557,10 +557,10 @@ async function unwrapKey( | |||
| 557 | 557 | extractable, | |
| 558 | 558 | keyUsages) { | |
| 559 | 559 | wrappedKey = getArrayBufferOrView(wrappedKey, 'wrappedKey'); | |
| 560 | - | ||
| 560 | + unwrapAlgo = normalizeAlgorithm(unwrapAlgo); | ||
| 561 | 561 | let keyData = await cipherOrWrap( | |
| 562 | 562 | kWebCryptoCipherDecrypt, | |
| 563 | - normalizeAlgorithm(unwrapAlgo), | ||
| 563 | + unwrapAlgo, | ||
| 564 | 564 | unwrappingKey, | |
| 565 | 565 | wrappedKey, | |
| 566 | 566 | 'unwrapKey'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + if (!common.hasCrypto) | ||
| 6 | + common.skip('missing crypto'); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + | ||
| 10 | + const { | ||
| 11 | + normalizeAlgorithm, | ||
| 12 | + } = require('internal/crypto/util'); | ||
| 13 | + | ||
| 14 | + { | ||
| 15 | + // Check that normalizeAlgorithm does not add an undefined hash property | ||
| 16 | + assert.strictEqual('hash' in normalizeAlgorithm({ name: 'ECDH' }), false); | ||
| 17 | + assert.strictEqual('hash' in normalizeAlgorithm('ECDH'), false); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + { | ||
| 21 | + // Check that normalizeAlgorithm does not mutate object inputs | ||
| 22 | + const algorithm = { name: 'ECDH', hash: 'SHA-256' }; | ||
| 23 | + assert.strictEqual(normalizeAlgorithm(algorithm) !== algorithm, true); | ||
| 24 | + assert.deepStrictEqual(algorithm, { name: 'ECDH', hash: 'SHA-256' }); | ||
| 25 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments