(key, encoding, bufferOnly = false)
| 639 | } |
| 640 | |
| 641 | function prepareSecretKey(key, encoding, bufferOnly = false) { |
| 642 | if (!bufferOnly) { |
| 643 | if (isKeyObject(key)) { |
| 644 | const type = getKeyObjectType(key); |
| 645 | if (type !== 'secret') |
| 646 | throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(type, 'secret'); |
| 647 | return getKeyObjectHandle(key); |
| 648 | } |
| 649 | if (isCryptoKey(key)) { |
| 650 | emitDEP0203(); |
| 651 | const type = getCryptoKeyType(key); |
| 652 | if (type !== 'secret') |
| 653 | throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(type, 'secret'); |
| 654 | return getCryptoKeyHandle(key); |
| 655 | } |
| 656 | } |
| 657 | if (typeof key !== 'string' && |
| 658 | !isArrayBufferView(key) && |
| 659 | !isAnyArrayBuffer(key)) { |
| 660 | throw new ERR_INVALID_ARG_TYPE( |
| 661 | 'key', |
| 662 | getKeyTypes(!bufferOnly, bufferOnly), |
| 663 | key); |
| 664 | } |
| 665 | return getArrayBufferOrView(key, 'key', encoding); |
| 666 | } |
| 667 | |
| 668 | function createSecretKey(key, encoding) { |
| 669 | key = prepareSecretKey(key, encoding, true); |
no test coverage detected
searching dependent graphs…