Skip to content

Commit 25242b2

Browse files
committed
crypto: allow inspecting the prototype of a crypto key
This would fail so far due to accessing a undefined property.
1 parent f89baf2 commit 25242b2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/internal/crypto/keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ class CryptoKey {
762762
get type() {
763763
if (!(this instanceof CryptoKey))
764764
throw new ERR_INVALID_THIS('CryptoKey');
765-
return this[kKeyObject].type;
765+
return this[kKeyObject]?.type;
766766
}
767767

768768
get extractable() {

test/parallel/test-crypto-subtle-zero-length.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (!common.hasCrypto)
66
common.skip('missing crypto');
77

88
const assert = require('assert');
9+
const { inspect } = require('util');
910
const { subtle } = globalThis.crypto;
1011

1112
(async () => {
@@ -17,6 +18,18 @@ const { subtle } = globalThis.crypto;
1718
[ 'encrypt', 'decrypt' ]);
1819
assert(k instanceof CryptoKey);
1920

21+
// Inspecting the prototype should work.
22+
const inspected = inspect(Object.getPrototypeOf(k));
23+
assert.strictEqual(
24+
inspected,
25+
'CryptoKey {\n' +
26+
' type: undefined,\n' +
27+
' extractable: undefined,\n' +
28+
' algorithm: undefined,\n' +
29+
' usages: undefined\n' +
30+
'}'
31+
);
32+
2033
const e = await subtle.encrypt({
2134
name: 'AES-GCM',
2235
iv: new Uint8Array(12),

0 commit comments

Comments
 (0)