Skip to content

Commit 0a09337

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 0a09337

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/internal/crypto/keys.js

+1-1
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-inspect.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const common = require('../common');
2+
const { subtle } = require('crypto');
3+
const { strictEqual } = require('assert');
4+
5+
const promise = subtle.importKey('raw', Buffer.from([1,2,3]), {
6+
name:'HMAC', hash: 'SHA-256'
7+
}, true, ['sign','verify']);
8+
9+
promise.then(common.mustCall((key) => {
10+
const inspected = inspect(Object.getPrototypeOf(key));
11+
strictEqual(
12+
inspected,
13+
'CryptoKey {\n' +
14+
' type: undefined,\n' +
15+
' extractable: undefined,\n' +
16+
' algorithm: undefined,\n' +
17+
' usages: undefined\n' +
18+
'}'
19+
);
20+
}));

0 commit comments

Comments
 (0)