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 ed72d83

Browse filesBrowse files
Trottaddaleax
authored andcommitted
crypto: simplify KeyObject constructor
Inline a function that only gets called in the constructor. Make call to `super()` more straightforward in the process by removing conditional involving the function as it only ever returns `undefined` or else throws. That made the code a little hard to understand, as without looking at the function, one would likely expect it to return `true` on success rather than `undefined`. PR-URL: #35064 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 090f869 commit ed72d83
Copy full SHA for ed72d83

File tree

Expand file treeCollapse file tree

1 file changed

+6
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-8
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
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ for (const m of [[kKeyEncodingPKCS1, 'pkcs1'], [kKeyEncodingPKCS8, 'pkcs8'],
4343
[kKeyEncodingSPKI, 'spki'], [kKeyEncodingSEC1, 'sec1']])
4444
encodingNames[m[0]] = m[1];
4545

46-
function checkKeyTypeAndHandle(type, handle) {
47-
if (type !== 'secret' && type !== 'public' && type !== 'private')
48-
throw new ERR_INVALID_ARG_VALUE('type', type);
49-
if (typeof handle !== 'object' || !(handle instanceof KeyObjectHandle))
50-
throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle);
51-
}
52-
5346
// Creating the KeyObject class is a little complicated due to inheritance
5447
// and that fact that KeyObjects should be transferrable between threads,
5548
// which requires the KeyObject base class to be implemented in C++.
@@ -64,7 +57,12 @@ const [
6457
// Publicly visible KeyObject class.
6558
class KeyObject extends NativeKeyObject {
6659
constructor(type, handle) {
67-
super(checkKeyTypeAndHandle(type, handle) || handle);
60+
if (type !== 'secret' && type !== 'public' && type !== 'private')
61+
throw new ERR_INVALID_ARG_VALUE('type', type);
62+
if (typeof handle !== 'object' || !(handle instanceof KeyObjectHandle))
63+
throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle);
64+
65+
super(handle);
6866

6967
this[kKeyType] = type;
7068

0 commit comments

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