From e6047699eb587a8540a76c0ac77b2a835a86d7be Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 1 Jan 2023 12:49:54 +0100 Subject: [PATCH] crypto: add CryptoKey Symbol.toStringTag closes #45987 --- lib/internal/crypto/keys.js | 6 ++++++ test/parallel/test-webcrypto-keygen.js | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 968116d6bf2ea7..48fef964c65126 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -7,6 +7,7 @@ const { ObjectDefineProperties, ObjectSetPrototypeOf, Symbol, + SymbolToStringTag, Uint8Array, } = primordials; @@ -687,6 +688,11 @@ ObjectDefineProperties(CryptoKey.prototype, { extractable: kEnumerableProperty, algorithm: kEnumerableProperty, usages: kEnumerableProperty, + [SymbolToStringTag]: { + __proto__: null, + configurable: true, + value: 'CryptoKey', + }, }); // All internal code must use new InternalCryptoKey to create diff --git a/test/parallel/test-webcrypto-keygen.js b/test/parallel/test-webcrypto-keygen.js index 7cb02c9863f4eb..437255f17a8443 100644 --- a/test/parallel/test-webcrypto-keygen.js +++ b/test/parallel/test-webcrypto-keygen.js @@ -277,6 +277,8 @@ const vectors = { assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(privateKey.type, 'private'); + assert.strictEqual(publicKey.toString(), '[object CryptoKey]'); + assert.strictEqual(privateKey.toString(), '[object CryptoKey]'); assert.strictEqual(publicKey.extractable, true); assert.strictEqual(privateKey.extractable, true); assert.deepStrictEqual(publicKey.usages, publicUsages); @@ -439,6 +441,8 @@ const vectors = { assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(privateKey.type, 'private'); + assert.strictEqual(publicKey.toString(), '[object CryptoKey]'); + assert.strictEqual(privateKey.toString(), '[object CryptoKey]'); assert.strictEqual(publicKey.extractable, true); assert.strictEqual(privateKey.extractable, true); assert.deepStrictEqual(publicKey.usages, publicUsages); @@ -503,6 +507,7 @@ const vectors = { assert(isCryptoKey(key)); assert.strictEqual(key.type, 'secret'); + assert.strictEqual(key.toString(), '[object CryptoKey]'); assert.strictEqual(key.extractable, true); assert.deepStrictEqual(key.usages, usages); assert.strictEqual(key.algorithm.name, name); @@ -562,6 +567,7 @@ const vectors = { assert(isCryptoKey(key)); assert.strictEqual(key.type, 'secret'); + assert.strictEqual(key.toString(), '[object CryptoKey]'); assert.strictEqual(key.extractable, true); assert.deepStrictEqual(key.usages, usages); assert.strictEqual(key.algorithm.name, 'HMAC'); @@ -629,6 +635,8 @@ assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(privateKey.type, 'private'); + assert.strictEqual(publicKey.toString(), '[object CryptoKey]'); + assert.strictEqual(privateKey.toString(), '[object CryptoKey]'); assert.strictEqual(publicKey.extractable, true); assert.strictEqual(privateKey.extractable, true); assert.deepStrictEqual(publicKey.usages, publicUsages);