Skip to content

Commit 043d264

Browse files
committed
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]> Backport-PR-URL: #46340
1 parent 1e11247 commit 043d264

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/internal/crypto/keys.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,14 @@ class CryptoKey extends JSTransferable {
697697
}
698698
}
699699

700+
ObjectDefineProperties(CryptoKey.prototype, {
701+
[SymbolToStringTag]: {
702+
__proto__: null,
703+
configurable: true,
704+
value: 'CryptoKey',
705+
},
706+
});
707+
700708
// All internal code must use new InternalCryptoKey to create
701709
// CryptoKey instances. The CryptoKey class is exposed to end
702710
// user code but is not permitted to be constructed directly.

test/parallel/test-webcrypto-keygen.js

Lines changed: 8 additions & 0 deletions
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)