Skip to content

Commit 8b22310

Browse files
panvaRafaelGSS
authored andcommitted
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 e5f53b5 commit 8b22310

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/internal/crypto/keys.js

+5
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

+8
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ const vectors = {
277277

278278
assert.strictEqual(publicKey.type, 'public');
279279
assert.strictEqual(privateKey.type, 'private');
280+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
281+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
280282
assert.strictEqual(publicKey.extractable, true);
281283
assert.strictEqual(privateKey.extractable, true);
282284
assert.deepStrictEqual(publicKey.usages, publicUsages);
@@ -439,6 +441,8 @@ const vectors = {
439441

440442
assert.strictEqual(publicKey.type, 'public');
441443
assert.strictEqual(privateKey.type, 'private');
444+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
445+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
442446
assert.strictEqual(publicKey.extractable, true);
443447
assert.strictEqual(privateKey.extractable, true);
444448
assert.deepStrictEqual(publicKey.usages, publicUsages);
@@ -503,6 +507,7 @@ const vectors = {
503507
assert(isCryptoKey(key));
504508

505509
assert.strictEqual(key.type, 'secret');
510+
assert.strictEqual(key.toString(), '[object CryptoKey]');
506511
assert.strictEqual(key.extractable, true);
507512
assert.deepStrictEqual(key.usages, usages);
508513
assert.strictEqual(key.algorithm.name, name);
@@ -562,6 +567,7 @@ const vectors = {
562567
assert(isCryptoKey(key));
563568

564569
assert.strictEqual(key.type, 'secret');
570+
assert.strictEqual(key.toString(), '[object CryptoKey]');
565571
assert.strictEqual(key.extractable, true);
566572
assert.deepStrictEqual(key.usages, usages);
567573
assert.strictEqual(key.algorithm.name, 'HMAC');
@@ -629,6 +635,8 @@ assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
629635

630636
assert.strictEqual(publicKey.type, 'public');
631637
assert.strictEqual(privateKey.type, 'private');
638+
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
639+
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
632640
assert.strictEqual(publicKey.extractable, true);
633641
assert.strictEqual(privateKey.extractable, true);
634642
assert.deepStrictEqual(publicKey.usages, publicUsages);

0 commit comments

Comments
 (0)