Skip to content

Commit bb7f71a

Browse files
tniessenaddaleax
authored andcommitted
crypto: fix key handle extraction
PR-URL: #25562 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 4e52b07 commit bb7f71a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/internal/crypto/keys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function parsePrivateKeyEncoding(enc, keyType, objName) {
215215

216216
function getKeyObjectHandle(key, isPublic, allowKeyObject) {
217217
if (!allowKeyObject) {
218-
return new ERR_INVALID_ARG_TYPE(
218+
throw new ERR_INVALID_ARG_TYPE(
219219
'key',
220220
['string', 'Buffer', 'TypedArray', 'DataView'],
221221
key

test/parallel/test-crypto-key-objects.js

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
5858
assert(plaintext.equals(deciphered));
5959
}
6060

61+
{
62+
// Passing an existing key object should throw.
63+
const publicKey = createPublicKey(publicPem);
64+
common.expectsError(() => createPublicKey(publicKey), {
65+
type: TypeError,
66+
code: 'ERR_INVALID_ARG_TYPE',
67+
message: 'The "key" argument must be one of type string, Buffer, ' +
68+
'TypedArray, or DataView. Received type object'
69+
});
70+
}
71+
6172
{
6273
const publicKey = createPublicKey(publicPem);
6374
assert.strictEqual(publicKey.type, 'public');

0 commit comments

Comments
 (0)