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

Function c20pImportKey

lib/internal/crypto/chacha20_poly1305.js:62–107  ·  view source on GitHub ↗
(
  algorithm,
  format,
  keyData,
  extractable,
  usages)

Source from the content-addressed store, hash-verified

60}
61
62function c20pImportKey(
63 algorithm,
64 format,
65 keyData,
66 extractable,
67 usages) {
68 const { name } = algorithm;
69
70 const usagesSet = validateKeyUsages(
71 usages, kUsages, name);
72
73 let handle;
74 switch (format) {
75 case 'KeyObjectHandle': {
76 handle = keyData;
77 break;
78 }
79 case 'raw-secret': {
80 handle = importSecretKey(keyData);
81 break;
82 }
83 case 'jwk': {
84 validateJwk(keyData, 'oct', extractable, usagesSet, 'enc');
85
86 handle = importJwkSecretKey(keyData);
87
88 if (keyData.alg !== undefined && keyData.alg !== 'C20P') {
89 throw lazyDOMException(
90 'JWK "alg" does not match the requested algorithm',
91 'DataError');
92 }
93
94 break;
95 }
96 default:
97 return undefined;
98 }
99
100 validateKeyLength(handle.getSymmetricKeySize() * 8);
101
102 return new InternalCryptoKey(
103 handle,
104 { name },
105 getUsagesMask(usagesSet),
106 extractable);
107}
108
109module.exports = {
110 c20pCipher,

Callers

nothing calls this directly

Calls 7

validateKeyUsagesFunction · 0.85
importSecretKeyFunction · 0.85
validateJwkFunction · 0.85
importJwkSecretKeyFunction · 0.85
lazyDOMExceptionFunction · 0.85
getUsagesMaskFunction · 0.85
validateKeyLengthFunction · 0.70

Tested by

no test coverage detected