Skip to content

Commit 6b1cc1d

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 6b1cc1d

File tree

2 files changed

+22
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)