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

Function encapsulateBitsImpl

lib/internal/crypto/webcrypto.js:1353–1392  ·  view source on GitHub ↗
(encapsulationAlgorithm, encapsulationKey)

Source from the content-addressed store, hash-verified

1351}
1352
1353function encapsulateBitsImpl(encapsulationAlgorithm, encapsulationKey) {
1354 emitExperimentalWarning('The encapsulateBits Web Crypto API method');
1355 const prefix = prepareSubtleMethod(
1356 this, 'encapsulateBits', arguments.length, 2);
1357 let i = 0;
1358 encapsulationAlgorithm = convertSubtleArgument(
1359 prefix, 'AlgorithmIdentifier', encapsulationAlgorithm, i++);
1360 encapsulationKey = convertSubtleArgument(
1361 prefix, 'CryptoKey', encapsulationKey, i++);
1362
1363 const normalizedEncapsulationAlgorithm =
1364 normalizeAlgorithm(encapsulationAlgorithm, 'encapsulate');
1365 const keyAlgorithm = getCryptoKeyAlgorithm(encapsulationKey);
1366
1367 if (normalizedEncapsulationAlgorithm.name !== keyAlgorithm.name) {
1368 throw lazyDOMException(
1369 'key algorithm mismatch',
1370 'InvalidAccessError');
1371 }
1372
1373 if (!hasCryptoKeyUsage(encapsulationKey, 'encapsulateBits')) {
1374 throw lazyDOMException(
1375 'encapsulationKey does not have encapsulateBits usage',
1376 'InvalidAccessError');
1377 }
1378
1379 switch (keyAlgorithm.name) {
1380 case 'ML-KEM-512':
1381 case 'ML-KEM-768':
1382 case 'ML-KEM-1024':
1383 return require('internal/crypto/ml_kem')
1384 .mlKemEncapsulate(encapsulationKey);
1385 /* c8 ignore start */
1386 default: {
1387 const assert = require('internal/assert');
1388 assert.fail('Unreachable code');
1389 }
1390 /* c8 ignore stop */
1391 }
1392}
1393
1394function encapsulateKey(
1395 encapsulationAlgorithm,

Callers

nothing calls this directly

Calls 9

emitExperimentalWarningFunction · 0.85
prepareSubtleMethodFunction · 0.85
convertSubtleArgumentFunction · 0.85
getCryptoKeyAlgorithmFunction · 0.85
lazyDOMExceptionFunction · 0.85
hasCryptoKeyUsageFunction · 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…