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

Function encapsulateKeyImpl

lib/internal/crypto/webcrypto.js:1403–1473  ·  view source on GitHub ↗
(
  encapsulationAlgorithm,
  encapsulationKey,
  sharedKeyAlgorithm,
  extractable,
  keyUsages)

Source from the content-addressed store, hash-verified

1401}
1402
1403function encapsulateKeyImpl(
1404 encapsulationAlgorithm,
1405 encapsulationKey,
1406 sharedKeyAlgorithm,
1407 extractable,
1408 keyUsages) {
1409 emitExperimentalWarning('The encapsulateKey Web Crypto API method');
1410 const prefix = prepareSubtleMethod(
1411 this, 'encapsulateKey', arguments.length, 5);
1412 let i = 0;
1413 encapsulationAlgorithm = convertSubtleArgument(
1414 prefix, 'AlgorithmIdentifier', encapsulationAlgorithm, i++);
1415 encapsulationKey = convertSubtleArgument(
1416 prefix, 'CryptoKey', encapsulationKey, i++);
1417 sharedKeyAlgorithm = convertSubtleArgument(
1418 prefix, 'AlgorithmIdentifier', sharedKeyAlgorithm, i++);
1419 extractable = convertSubtleArgument(prefix, 'boolean', extractable, i++);
1420 const usages = convertSubtleArgument(
1421 prefix, 'sequence<KeyUsage>', keyUsages, i++);
1422
1423 const normalizedEncapsulationAlgorithm =
1424 normalizeAlgorithm(encapsulationAlgorithm, 'encapsulate');
1425 const normalizedSharedKeyAlgorithm =
1426 normalizeAlgorithm(sharedKeyAlgorithm, 'importKey');
1427 const keyAlgorithm = getCryptoKeyAlgorithm(encapsulationKey);
1428
1429 if (normalizedEncapsulationAlgorithm.name !== keyAlgorithm.name) {
1430 throw lazyDOMException(
1431 'key algorithm mismatch',
1432 'InvalidAccessError');
1433 }
1434
1435 if (!hasCryptoKeyUsage(encapsulationKey, 'encapsulateKey')) {
1436 throw lazyDOMException(
1437 'encapsulationKey does not have encapsulateKey usage',
1438 'InvalidAccessError');
1439 }
1440
1441 let encapsulatedBits;
1442 switch (keyAlgorithm.name) {
1443 case 'ML-KEM-512':
1444 case 'ML-KEM-768':
1445 case 'ML-KEM-1024':
1446 encapsulatedBits = require('internal/crypto/ml_kem')
1447 .mlKemEncapsulate(encapsulationKey);
1448 break;
1449 /* c8 ignore start */
1450 default: {
1451 const assert = require('internal/assert');
1452 assert.fail('Unreachable code');
1453 }
1454 /* c8 ignore stop */
1455 }
1456
1457 return jobPromiseThen(encapsulatedBits, (encapsulatedBits) => {
1458 const sharedKey = FunctionPrototypeCall(
1459 importKeySync,
1460 this,

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…