Skip to content

Commit

Permalink
crypto: fix key handle extraction
Browse files Browse the repository at this point in the history
PR-URL: #25562
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
tniessen authored and addaleax committed Jan 23, 2019
1 parent 4e52b07 commit bb7f71a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function parsePrivateKeyEncoding(enc, keyType, objName) {

function getKeyObjectHandle(key, isPublic, allowKeyObject) {
if (!allowKeyObject) {
return new ERR_INVALID_ARG_TYPE(
throw new ERR_INVALID_ARG_TYPE(
'key',
['string', 'Buffer', 'TypedArray', 'DataView'],
key
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-crypto-key-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
assert(plaintext.equals(deciphered));
}

{
// Passing an existing key object should throw.
const publicKey = createPublicKey(publicPem);
common.expectsError(() => createPublicKey(publicKey), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
});
}

{
const publicKey = createPublicKey(publicPem);
assert.strictEqual(publicKey.type, 'public');
Expand Down

0 comments on commit bb7f71a

Please sign in to comment.