Skip to content
/ node Public
forked from nodejs/node

Commit

Permalink
crypto: add CryptoKey Symbol.toStringTag
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jan 1, 2023
1 parent 4830a6c commit 4a830d9
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
@@ -680,6 +680,10 @@ class CryptoKey {
throw new ERR_INVALID_THIS('CryptoKey');
return ArrayFrom(this[kKeyUsages]);
}

get [Symbol.toStringTag]() {
return 'CryptoKey';
}
}

ObjectDefineProperties(CryptoKey.prototype, {
8 changes: 8 additions & 0 deletions test/parallel/test-webcrypto-keygen.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 4a830d9

Please sign in to comment.