(key, format)
| 80 | } |
| 81 | |
| 82 | function mlKemExportKey(key, format) { |
| 83 | try { |
| 84 | const handle = getCryptoKeyHandle(key); |
| 85 | switch (format) { |
| 86 | case kWebCryptoKeyFormatRaw: { |
| 87 | return TypedArrayPrototypeGetBuffer( |
| 88 | getCryptoKeyType(key) === 'private' ? handle.rawSeed() : handle.rawPublicKey()); |
| 89 | } |
| 90 | case kWebCryptoKeyFormatSPKI: { |
| 91 | return TypedArrayPrototypeGetBuffer( |
| 92 | handle.export(kKeyFormatDER, kWebCryptoKeyFormatSPKI)); |
| 93 | } |
| 94 | case kWebCryptoKeyFormatPKCS8: { |
| 95 | const pkcs8 = handle.export( |
| 96 | kKeyFormatDER, kWebCryptoKeyFormatPKCS8, null, null); |
| 97 | // Edge case only possible when user creates a seedless KeyObject |
| 98 | // first and converts it with KeyObject.prototype.toCryptoKey. |
| 99 | // 86 = 22 bytes of PKCS#8 ASN.1 + 64-byte seed. |
| 100 | if (TypedArrayPrototypeGetByteLength(pkcs8) !== 86) { |
| 101 | throw lazyDOMException( |
| 102 | 'The operation failed for an operation-specific reason', |
| 103 | { name: 'OperationError' }); |
| 104 | } |
| 105 | return TypedArrayPrototypeGetBuffer(pkcs8); |
| 106 | } |
| 107 | default: |
| 108 | return undefined; |
| 109 | } |
| 110 | } catch (err) { |
| 111 | throw lazyDOMException( |
| 112 | 'The operation failed for an operation-specific reason', |
| 113 | { name: 'OperationError', cause: err }); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | function mlKemImportKey( |
| 118 | format, |
nothing calls this directly
no test coverage detected
searching dependent graphs…