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

Function parseKeyType

lib/internal/crypto/keys.js:368–390  ·  view source on GitHub ↗
(typeStr, required, keyType, isPublic, optionName)

Source from the content-addressed store, hash-verified

366}
367
368function parseKeyType(typeStr, required, keyType, isPublic, optionName) {
369 if (typeStr === undefined && !required) {
370 return undefined;
371 } else if (typeStr === 'pkcs1') {
372 if (keyType !== undefined && keyType !== 'rsa') {
373 throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(
374 typeStr, 'can only be used for RSA keys');
375 }
376 return kKeyEncodingPKCS1;
377 } else if (typeStr === 'spki' && isPublic !== false) {
378 return kKeyEncodingSPKI;
379 } else if (typeStr === 'pkcs8' && isPublic !== true) {
380 return kKeyEncodingPKCS8;
381 } else if (typeStr === 'sec1' && isPublic !== true) {
382 if (keyType !== undefined && keyType !== 'ec') {
383 throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(
384 typeStr, 'can only be used for EC keys');
385 }
386 return kKeyEncodingSEC1;
387 }
388
389 throw new ERR_INVALID_ARG_VALUE(optionName, typeStr);
390}
391
392function option(name, prefix) {
393 return prefix === undefined ?

Callers 1

parseKeyFormatAndTypeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected