(encapsulationAlgorithm, encapsulationKey)
| 1351 | } |
| 1352 | |
| 1353 | function 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 | |
| 1394 | function encapsulateKey( |
| 1395 | encapsulationAlgorithm, |
nothing calls this directly
no test coverage detected
searching dependent graphs…