| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,30 +206,33 @@ 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'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -587,10 +587,10 @@ async function unwrapKey( | |||
| 587 | 587 | extractable, | |
| 588 | 588 | keyUsages) { | |
| 589 | 589 | wrappedKey = getArrayBufferOrView(wrappedKey, 'wrappedKey'); | |
| 590 | - | ||
| 590 | + unwrapAlgo = normalizeAlgorithm(unwrapAlgo); | ||
| 591 | 591 | let keyData = await cipherOrWrap( | |
| 592 | 592 | kWebCryptoCipherDecrypt, | |
| 593 | - normalizeAlgorithm(unwrapAlgo), | ||
| 593 | + unwrapAlgo, | ||
| 594 | 594 | unwrappingKey, | |
| 595 | 595 | wrappedKey, | |
| 596 | 596 | '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