Skip to content

Commit

Permalink
crypto: fix CryptoKey WebIDL conformance
Browse files Browse the repository at this point in the history
PR-URL: #45855
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
panva authored and juanarbol committed Jan 24, 2023
1 parent c643645 commit 1a8aa50
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/internal/crypto/keys.js
Expand Up @@ -4,6 +4,7 @@ const {
ArrayFrom,
ArrayPrototypeSlice,
ObjectDefineProperty,
ObjectDefineProperties,
ObjectSetPrototypeOf,
Symbol,
Uint8Array,
Expand Down Expand Up @@ -38,6 +39,7 @@ const {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_THIS,
}
} = require('internal/errors');

Expand All @@ -61,6 +63,7 @@ const {

const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const { inspect } = require('internal/util/inspect');
Expand Down Expand Up @@ -657,18 +660,26 @@ class CryptoKey extends JSTransferable {
}

get type() {
if (!(this instanceof CryptoKey))
throw new ERR_INVALID_THIS('CryptoKey');
return this[kKeyObject].type;
}

get extractable() {
if (!(this instanceof CryptoKey))
throw new ERR_INVALID_THIS('CryptoKey');
return this[kExtractable];
}

get algorithm() {
if (!(this instanceof CryptoKey))
throw new ERR_INVALID_THIS('CryptoKey');
return this[kAlgorithm];
}

get usages() {
if (!(this instanceof CryptoKey))
throw new ERR_INVALID_THIS('CryptoKey');
return ArrayFrom(this[kKeyUsages]);
}

Expand Down Expand Up @@ -697,6 +708,13 @@ class CryptoKey extends JSTransferable {
}
}

ObjectDefineProperties(CryptoKey.prototype, {
type: kEnumerableProperty,
extractable: kEnumerableProperty,
algorithm: kEnumerableProperty,
usages: kEnumerableProperty,
});

// All internal code must use new InternalCryptoKey to create
// CryptoKey instances. The CryptoKey class is exposed to end
// user code but is not permitted to be constructed directly.
Expand Down

0 comments on commit 1a8aa50

Please sign in to comment.