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

Function parseKeyFormatAndType

lib/internal/crypto/keys.js:397–441  ·  view source on GitHub ↗
(enc, keyType, isPublic, objName)

Source from the content-addressed store, hash-verified

395}
396
397function parseKeyFormatAndType(enc, keyType, isPublic, objName) {
398 const { format: formatStr, type: typeStr } = enc;
399
400 const isInput = keyType === undefined;
401 const format = parseKeyFormat(formatStr,
402 isInput ? kKeyFormatPEM : undefined,
403 option('format', objName));
404
405 if (format === kKeyFormatRawPublic) {
406 if (isPublic === false) {
407 throw new ERR_INVALID_ARG_VALUE(option('format', objName), 'raw-public');
408 }
409 let type;
410 if (typeStr === undefined || typeStr === 'uncompressed') {
411 type = POINT_CONVERSION_UNCOMPRESSED;
412 } else if (typeStr === 'compressed') {
413 type = POINT_CONVERSION_COMPRESSED;
414 } else {
415 throw new ERR_INVALID_ARG_VALUE(option('type', objName), typeStr);
416 }
417 return { format, type };
418 }
419
420 if (format === kKeyFormatRawPrivate || format === kKeyFormatRawSeed) {
421 if (isPublic === true) {
422 throw new ERR_INVALID_ARG_VALUE(
423 option('format', objName),
424 format === kKeyFormatRawPrivate ? 'raw-private' : 'raw-seed');
425 }
426 if (typeStr !== undefined) {
427 throw new ERR_INVALID_ARG_VALUE(option('type', objName), typeStr);
428 }
429 return { format };
430 }
431
432 const isRequired = (!isInput ||
433 format === kKeyFormatDER) &&
434 format !== kKeyFormatJWK;
435 const type = parseKeyType(typeStr,
436 isRequired,
437 keyType,
438 isPublic,
439 option('type', objName));
440 return { format, type };
441}
442
443function isStringOrBuffer(val) {
444 return typeof val === 'string' ||

Callers 1

parseKeyEncodingFunction · 0.85

Calls 3

parseKeyFormatFunction · 0.85
optionFunction · 0.85
parseKeyTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…