MCPcopy Index your code
hub / github.com/nodejs/node / decapsulateKeyImpl

Function decapsulateKeyImpl

lib/internal/crypto/webcrypto.js:1531–1596  ·  view source on GitHub ↗
(
  decapsulationAlgorithm,
  decapsulationKey,
  ciphertext,
  sharedKeyAlgorithm,
  extractable,
  keyUsages)

Source from the content-addressed store, hash-verified

1529}
1530
1531function decapsulateKeyImpl(
1532 decapsulationAlgorithm,
1533 decapsulationKey,
1534 ciphertext,
1535 sharedKeyAlgorithm,
1536 extractable,
1537 keyUsages) {
1538 emitExperimentalWarning('The decapsulateKey Web Crypto API method');
1539 const prefix = prepareSubtleMethod(
1540 this, 'decapsulateKey', arguments.length, 6);
1541 let i = 0;
1542 decapsulationAlgorithm = convertSubtleArgument(
1543 prefix, 'AlgorithmIdentifier', decapsulationAlgorithm, i++);
1544 decapsulationKey = convertSubtleArgument(
1545 prefix, 'CryptoKey', decapsulationKey, i++);
1546 ciphertext = convertSubtleArgument(prefix, 'BufferSource', ciphertext, i++);
1547 sharedKeyAlgorithm = convertSubtleArgument(
1548 prefix, 'AlgorithmIdentifier', sharedKeyAlgorithm, i++);
1549 extractable = convertSubtleArgument(prefix, 'boolean', extractable, i++);
1550 const usages = convertSubtleArgument(
1551 prefix, 'sequence<KeyUsage>', keyUsages, i++);
1552
1553 const normalizedDecapsulationAlgorithm =
1554 normalizeAlgorithm(decapsulationAlgorithm, 'decapsulate');
1555 const normalizedSharedKeyAlgorithm =
1556 normalizeAlgorithm(sharedKeyAlgorithm, 'importKey');
1557 const keyAlgorithm = getCryptoKeyAlgorithm(decapsulationKey);
1558
1559 if (normalizedDecapsulationAlgorithm.name !== keyAlgorithm.name) {
1560 throw lazyDOMException(
1561 'key algorithm mismatch',
1562 'InvalidAccessError');
1563 }
1564
1565 if (!hasCryptoKeyUsage(decapsulationKey, 'decapsulateKey')) {
1566 throw lazyDOMException(
1567 'decapsulationKey does not have decapsulateKey usage',
1568 'InvalidAccessError');
1569 }
1570
1571 let decapsulatedBits;
1572 switch (keyAlgorithm.name) {
1573 case 'ML-KEM-512':
1574 case 'ML-KEM-768':
1575 case 'ML-KEM-1024':
1576 decapsulatedBits = require('internal/crypto/ml_kem')
1577 .mlKemDecapsulate(decapsulationKey, ciphertext);
1578 break;
1579 /* c8 ignore start */
1580 default: {
1581 const assert = require('internal/assert');
1582 assert.fail('Unreachable code');
1583 }
1584 /* c8 ignore stop */
1585 }
1586
1587 return jobPromiseThen(decapsulatedBits, (decapsulatedBits) => FunctionPrototypeCall(
1588 importKeySync,

Callers

nothing calls this directly

Calls 10

emitExperimentalWarningFunction · 0.85
prepareSubtleMethodFunction · 0.85
convertSubtleArgumentFunction · 0.85
getCryptoKeyAlgorithmFunction · 0.85
lazyDOMExceptionFunction · 0.85
hasCryptoKeyUsageFunction · 0.85
jobPromiseThenFunction · 0.85
normalizeAlgorithmFunction · 0.70
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…