(typeStr, required, keyType, isPublic, optionName)
| 366 | } |
| 367 | |
| 368 | function 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 | |
| 392 | function option(name, prefix) { |
| 393 | return prefix === undefined ? |
no outgoing calls
no test coverage detected