(enc, keyType, isPublic, objName)
| 395 | } |
| 396 | |
| 397 | function 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 | |
| 443 | function isStringOrBuffer(val) { |
| 444 | return typeof val === 'string' || |
no test coverage detected
searching dependent graphs…