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

Function mlDsaExportKey

lib/internal/crypto/ml_dsa.js:81–114  ·  view source on GitHub ↗
(key, format)

Source from the content-addressed store, hash-verified

79}
80
81function 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
116function mlDsaImportKey(
117 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…