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