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 2de50fe

Browse filesBrowse files
panvajuanarbol
authored andcommitted
crypto: add KeyObject Symbol.toStringTag
PR-URL: #46043 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 4df1fcc commit 2de50fe
Copy full SHA for 2de50fe

File tree

Expand file treeCollapse file tree

2 files changed

+15
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-0
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
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
ObjectDefineProperties,
88
ObjectSetPrototypeOf,
99
Symbol,
10+
SymbolToStringTag,
1011
Uint8Array,
1112
} = primordials;
1213

@@ -139,6 +140,14 @@ const {
139140
}
140141
}
141142

143+
ObjectDefineProperties(KeyObject.prototype, {
144+
[SymbolToStringTag]: {
145+
__proto__: null,
146+
configurable: true,
147+
value: 'KeyObject',
148+
},
149+
});
150+
142151
class SecretKeyObject extends KeyObject {
143152
constructor(handle) {
144153
super('secret', handle);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-key-objects.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
6969
const keybuf = randomBytes(32);
7070
const key = createSecretKey(keybuf);
7171
assert.strictEqual(key.type, 'secret');
72+
assert.strictEqual(key.toString(), '[object KeyObject]');
7273
assert.strictEqual(key.symmetricKeySize, 32);
7374
assert.strictEqual(key.asymmetricKeyType, undefined);
7475
assert.strictEqual(key.asymmetricKeyDetails, undefined);
@@ -150,27 +151,32 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
150151

151152
const publicKey = createPublicKey(publicPem);
152153
assert.strictEqual(publicKey.type, 'public');
154+
assert.strictEqual(publicKey.toString(), '[object KeyObject]');
153155
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
154156
assert.strictEqual(publicKey.symmetricKeySize, undefined);
155157

156158
const privateKey = createPrivateKey(privatePem);
157159
assert.strictEqual(privateKey.type, 'private');
160+
assert.strictEqual(privateKey.toString(), '[object KeyObject]');
158161
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
159162
assert.strictEqual(privateKey.symmetricKeySize, undefined);
160163

161164
// It should be possible to derive a public key from a private key.
162165
const derivedPublicKey = createPublicKey(privateKey);
163166
assert.strictEqual(derivedPublicKey.type, 'public');
167+
assert.strictEqual(derivedPublicKey.toString(), '[object KeyObject]');
164168
assert.strictEqual(derivedPublicKey.asymmetricKeyType, 'rsa');
165169
assert.strictEqual(derivedPublicKey.symmetricKeySize, undefined);
166170

167171
const publicKeyFromJwk = createPublicKey({ key: publicJwk, format: 'jwk' });
168172
assert.strictEqual(publicKey.type, 'public');
173+
assert.strictEqual(publicKey.toString(), '[object KeyObject]');
169174
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
170175
assert.strictEqual(publicKey.symmetricKeySize, undefined);
171176

172177
const privateKeyFromJwk = createPrivateKey({ key: jwk, format: 'jwk' });
173178
assert.strictEqual(privateKey.type, 'private');
179+
assert.strictEqual(privateKey.toString(), '[object KeyObject]');
174180
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
175181
assert.strictEqual(privateKey.symmetricKeySize, undefined);
176182

0 commit comments

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