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

Function importGenericSecretKey

lib/internal/crypto/keys.js:1251–1290  ·  view source on GitHub ↗
(
  algorithm,
  format,
  keyData,
  extractable,
  keyUsages,
)

Source from the content-addressed store, hash-verified

1249}
1250
1251function importGenericSecretKey(
1252 algorithm,
1253 format,
1254 keyData,
1255 extractable,
1256 keyUsages,
1257) {
1258 const usagesSet = new SafeSet(keyUsages);
1259 const { name } = algorithm;
1260 if (extractable)
1261 throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError');
1262
1263 if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) {
1264 throw lazyDOMException(
1265 `Unsupported key usage for a ${name} key`,
1266 'SyntaxError');
1267 }
1268
1269 let handle;
1270 switch (format) {
1271 case 'KeyObjectHandle': {
1272 handle = keyData;
1273 break;
1274 }
1275 case 'raw-secret':
1276 case 'raw': {
1277 handle = new KeyObjectHandle();
1278 handle.init(kKeyTypeSecret, keyData);
1279 break;
1280 }
1281 default:
1282 return undefined;
1283 }
1284
1285 return new InternalCryptoKey(
1286 handle,
1287 { name },
1288 getUsagesMask(usagesSet),
1289 false);
1290}
1291
1292module.exports = {
1293 // Public API.

Callers 2

importKeySyncFunction · 0.85
toCryptoKeySecretFunction · 0.85

Calls 4

lazyDOMExceptionFunction · 0.85
hasAnyNotInFunction · 0.85
getUsagesMaskFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…