Skip to content

Commit 13f518f

Browse files
authored
crypto: add CryptoKey Symbol.toStringTag
closes #45987 PR-URL: #46042 Fixes: #45987 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent ad16a75 commit 13f518f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/internal/crypto/keys.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ ObjectDefineProperties(CryptoKey.prototype, {
696696
extractable: kEnumerableProperty,
697697
algorithm: kEnumerableProperty,
698698
usages: kEnumerableProperty,
699+
[SymbolToStringTag]: {
700+
__proto__: null,
701+
configurable: true,
702+
value: 'CryptoKey',
703+
},
699704
});
700705

701706
// All internal code must use new InternalCryptoKey to create

test/parallel/test-webcrypto-keygen.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ const vectors = {
278278

279279
assert.strictEqual(publicKey.type, 'public');
280280
assert.strictEqual(privateKey.type, 'private');
281+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
282+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
281283
assert.strictEqual(publicKey.extractable, true);
282284
assert.strictEqual(privateKey.extractable, true);
283285
assert.deepStrictEqual(publicKey.usages, publicUsages);
@@ -430,6 +432,8 @@ const vectors = {
430432

431433
assert.strictEqual(publicKey.type, 'public');
432434
assert.strictEqual(privateKey.type, 'private');
435+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
436+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
433437
assert.strictEqual(publicKey.extractable, true);
434438
assert.strictEqual(privateKey.extractable, true);
435439
assert.deepStrictEqual(publicKey.usages, publicUsages);
@@ -499,6 +503,7 @@ const vectors = {
499503
assert(isCryptoKey(key));
500504

501505
assert.strictEqual(key.type, 'secret');
506+
assert.strictEqual(key.toString(), '[object CryptoKey]');
502507
assert.strictEqual(key.extractable, true);
503508
assert.deepStrictEqual(key.usages, usages);
504509
assert.strictEqual(key.algorithm.name, name);
@@ -557,6 +562,7 @@ const vectors = {
557562
assert(isCryptoKey(key));
558563

559564
assert.strictEqual(key.type, 'secret');
565+
assert.strictEqual(key.toString(), '[object CryptoKey]');
560566
assert.strictEqual(key.extractable, true);
561567
assert.deepStrictEqual(key.usages, usages);
562568
assert.strictEqual(key.algorithm.name, 'HMAC');
@@ -618,6 +624,8 @@ assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
618624

619625
assert.strictEqual(publicKey.type, 'public');
620626
assert.strictEqual(privateKey.type, 'private');
627+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
628+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
621629
assert.strictEqual(publicKey.extractable, true);
622630
assert.strictEqual(privateKey.extractable, true);
623631
assert.deepStrictEqual(publicKey.usages, publicUsages);

0 commit comments

Comments
 (0)