From 4a830d9c76c87dba5ffcbb50f780c1d42e7c9d61 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 | 4 ++++ test/parallel/test-webcrypto-keygen.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 968116d6bf2ea7..f5f2892d525a6a 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -680,6 +680,10 @@ class CryptoKey { throw new ERR_INVALID_THIS('CryptoKey'); return ArrayFrom(this[kKeyUsages]); } + + get [Symbol.toStringTag]() { + return 'CryptoKey'; + } } ObjectDefineProperties(CryptoKey.prototype, { 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);