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

Function mlKemExportKey

lib/internal/crypto/ml_kem.js:82–115  ·  view source on GitHub ↗
(key, format)

Source from the content-addressed store, hash-verified

80}
81
82function 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
117function mlKemImportKey(
118 format,

Callers

nothing calls this directly

Calls 4

getCryptoKeyHandleFunction · 0.85
getCryptoKeyTypeFunction · 0.85
lazyDOMExceptionFunction · 0.85
exportMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…