Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9220a68

Browse filesBrowse files
pinguinjkeketargos
authored andcommitted
crypto: fix KeyObject handle type error message
Fix KeyObject handle type error message. Add test to cover KeyObject ERR_INVALID_ARG_TYPE exception. PR-URL: #27904 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 33236b7 commit 9220a68
Copy full SHA for 9220a68

File tree

Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/keys.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/keys.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class KeyObject {
4444
if (type !== 'secret' && type !== 'public' && type !== 'private')
4545
throw new ERR_INVALID_ARG_VALUE('type', type);
4646
if (typeof handle !== 'object')
47-
throw new ERR_INVALID_ARG_TYPE('handle', 'string', handle);
47+
throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle);
4848

4949
this[kKeyType] = type;
5050

Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-key-objects.js
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
createSecretKey,
1414
createPublicKey,
1515
createPrivateKey,
16+
KeyObject,
1617
randomBytes,
1718
publicEncrypt,
1819
privateDecrypt
@@ -39,6 +40,27 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
3940
});
4041
}
4142

43+
{
44+
// Attempting to create a key of a wrong type should throw
45+
const TYPE = 'wrong_type';
46+
47+
common.expectsError(() => new KeyObject(TYPE), {
48+
type: TypeError,
49+
code: 'ERR_INVALID_ARG_VALUE',
50+
message: `The argument 'type' is invalid. Received '${TYPE}'`
51+
});
52+
}
53+
54+
{
55+
// Attempting to create a key with non-object handle should throw
56+
common.expectsError(() => new KeyObject('secret', ''), {
57+
type: TypeError,
58+
code: 'ERR_INVALID_ARG_TYPE',
59+
message:
60+
'The "handle" argument must be of type object. Received type string'
61+
});
62+
}
63+
4264
{
4365
const keybuf = randomBytes(32);
4466
const key = createSecretKey(keybuf);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.