Skip to content

Commit bb7f71a

Browse files
tniessenaddaleax
authored andcommitted
crypto: fix key handle extraction
PR-URL: #25562 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 4e52b07 commit bb7f71a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎lib/internal/crypto/keys.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function parsePrivateKeyEncoding(enc, keyType, objName) {
215215

216216
functiongetKeyObjectHandle(key,isPublic,allowKeyObject){
217217
if(!allowKeyObject){
218-
returnnewERR_INVALID_ARG_TYPE(
218+
thrownewERR_INVALID_ARG_TYPE(
219219
'key',
220220
['string','Buffer','TypedArray','DataView'],
221221
key

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

Lines changed: 11 additions & 0 deletions
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+
constpublicKey=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
constpublicKey=createPublicKey(publicPem);
6374
assert.strictEqual(publicKey.type,'public');

0 commit comments

Comments
 (0)