(algorithm, op)
| 604 | // adapted for Node.js from Deno's implementation |
| 605 | // https://github.com/denoland/deno/blob/v1.29.1/ext/crypto/00_crypto.js#L195 |
| 606 | function normalizeAlgorithm(algorithm, op) { |
| 607 | if (typeof algorithm === 'string') |
| 608 | return normalizeAlgorithm({ name: algorithm }, op); |
| 609 | |
| 610 | webidl ??= require('internal/crypto/webidl'); |
| 611 | |
| 612 | // 1. |
| 613 | const registeredAlgorithms = kSupportedAlgorithms[op]; |
| 614 | // 2. 3. |
| 615 | const initialAlg = webidl.converters.Algorithm(algorithm, |
| 616 | kNormalizeAlgorithmOpts); |
| 617 | // 4. |
| 618 | let algName = initialAlg.name; |
| 619 | |
| 620 | // 5. Case-insensitive lookup via pre-built Map (O(1) instead of O(n)). |
| 621 | const canonicalName = kAlgorithmNameMap[op]?.get( |
| 622 | StringPrototypeToUpperCase(algName)); |
| 623 | if (canonicalName === undefined) |
| 624 | throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError'); |
| 625 | |
| 626 | algName = canonicalName; |
| 627 | const desiredType = registeredAlgorithms[algName]; |
| 628 | |
| 629 | // Fast path everything below if the registered dictionary is null |
| 630 | if (desiredType === null) |
| 631 | return { name: algName }; |
| 632 | |
| 633 | // 6. |
| 634 | const normalizedAlgorithm = webidl.converters[desiredType]( |
| 635 | { __proto__: algorithm, name: algName }, |
| 636 | kNormalizeAlgorithmOpts, |
| 637 | ); |
| 638 | // 7. |
| 639 | normalizedAlgorithm.name = algName; |
| 640 | |
| 641 | // 9. 10. Pre-computed keys and types from simpleAlgorithmDictionaries. |
| 642 | const dictMeta = simpleAlgorithmDictionaries[desiredType]; |
| 643 | if (dictMeta) { |
| 644 | const { keys: dictKeys, types: dictTypes } = dictMeta; |
| 645 | for (let i = 0; i < dictKeys.length; i++) { |
| 646 | const member = dictKeys[i]; |
| 647 | const idlType = dictTypes[member]; |
| 648 | const idlValue = normalizedAlgorithm[member]; |
| 649 | // 3. |
| 650 | if (idlType === 'BufferSource' && idlValue) { |
| 651 | const isView = ArrayBufferIsView(idlValue); |
| 652 | const idlValueBytes = isView ? |
| 653 | new Uint8Array( |
| 654 | getDataViewOrTypedArrayBuffer(idlValue), |
| 655 | getDataViewOrTypedArrayByteOffset(idlValue), |
| 656 | getDataViewOrTypedArrayByteLength(idlValue), |
| 657 | ) : |
| 658 | new Uint8Array( |
| 659 | idlValue, |
| 660 | 0, |
| 661 | ArrayBufferPrototypeGetByteLength(idlValue), |
| 662 | ); |
| 663 | normalizedAlgorithm[member] = TypedArrayPrototypeSlice( |
no test coverage detected
searching dependent graphs…