(decapsulationAlgorithm, decapsulationKey, ciphertext)
| 1477 | } |
| 1478 | |
| 1479 | function decapsulateBitsImpl(decapsulationAlgorithm, decapsulationKey, ciphertext) { |
| 1480 | emitExperimentalWarning('The decapsulateBits Web Crypto API method'); |
| 1481 | const prefix = prepareSubtleMethod( |
| 1482 | this, 'decapsulateBits', arguments.length, 3); |
| 1483 | let i = 0; |
| 1484 | decapsulationAlgorithm = convertSubtleArgument( |
| 1485 | prefix, 'AlgorithmIdentifier', decapsulationAlgorithm, i++); |
| 1486 | decapsulationKey = convertSubtleArgument( |
| 1487 | prefix, 'CryptoKey', decapsulationKey, i++); |
| 1488 | ciphertext = convertSubtleArgument(prefix, 'BufferSource', ciphertext, i++); |
| 1489 | |
| 1490 | const normalizedDecapsulationAlgorithm = |
| 1491 | normalizeAlgorithm(decapsulationAlgorithm, 'decapsulate'); |
| 1492 | const keyAlgorithm = getCryptoKeyAlgorithm(decapsulationKey); |
| 1493 | |
| 1494 | if (normalizedDecapsulationAlgorithm.name !== keyAlgorithm.name) { |
| 1495 | throw lazyDOMException( |
| 1496 | 'key algorithm mismatch', |
| 1497 | 'InvalidAccessError'); |
| 1498 | } |
| 1499 | |
| 1500 | if (!hasCryptoKeyUsage(decapsulationKey, 'decapsulateBits')) { |
| 1501 | throw lazyDOMException( |
| 1502 | 'decapsulationKey does not have decapsulateBits usage', |
| 1503 | 'InvalidAccessError'); |
| 1504 | } |
| 1505 | |
| 1506 | switch (keyAlgorithm.name) { |
| 1507 | case 'ML-KEM-512': |
| 1508 | case 'ML-KEM-768': |
| 1509 | case 'ML-KEM-1024': |
| 1510 | return require('internal/crypto/ml_kem') |
| 1511 | .mlKemDecapsulate(decapsulationKey, ciphertext); |
| 1512 | /* c8 ignore start */ |
| 1513 | default: { |
| 1514 | const assert = require('internal/assert'); |
| 1515 | assert.fail('Unreachable code'); |
| 1516 | } |
| 1517 | /* c8 ignore stop */ |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | function decapsulateKey( |
| 1522 | decapsulationAlgorithm, |
nothing calls this directly
no test coverage detected
searching dependent graphs…