mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
crypto: update CryptoKey symbol properties
PR-URL: https://github.com/nodejs/node/pull/50897 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
3f4fd6efbb
commit
e5017a522e
1 file changed
+65
-19
+65
-19
@@ -703,32 +703,81 @@ ObjectDefineProperties(CryptoKey.prototype, {
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {InternalCryptoKey} key
|
||||
* @param {KeyObject} keyObject
|
||||
* @param {object} algorithm
|
||||
* @param {boolean} extractable
|
||||
* @param {Set<string>} keyUsages
|
||||
*/
|
||||
function defineCryptoKeyProperties(
|
||||
key,
|
||||
keyObject,
|
||||
algorithm,
|
||||
extractable,
|
||||
keyUsages,
|
||||
) {
|
||||
// Using symbol properties here currently instead of private
|
||||
// properties because (for now) the performance penalty of
|
||||
// private fields is still too high.
|
||||
ObjectDefineProperties(key, {
|
||||
[kKeyObject]: {
|
||||
__proto__: null,
|
||||
value: keyObject,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
},
|
||||
[kAlgorithm]: {
|
||||
__proto__: null,
|
||||
value: algorithm,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
},
|
||||
[kExtractable]: {
|
||||
__proto__: null,
|
||||
value: extractable,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
},
|
||||
[kKeyUsages]: {
|
||||
__proto__: null,
|
||||
value: keyUsages,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Using markTransferMode also allows the CryptoKey to be
|
||||
// cloned to Workers.
|
||||
class InternalCryptoKey {
|
||||
constructor(
|
||||
keyObject,
|
||||
algorithm,
|
||||
keyUsages,
|
||||
extractable) {
|
||||
constructor(keyObject, algorithm, keyUsages, extractable) {
|
||||
markTransferMode(this, true, false);
|
||||
// Using symbol properties here currently instead of private
|
||||
// properties because (for now) the performance penalty of
|
||||
// private fields is still too high.
|
||||
this[kKeyObject] = keyObject;
|
||||
this[kAlgorithm] = algorithm;
|
||||
this[kExtractable] = extractable;
|
||||
this[kKeyUsages] = keyUsages;
|
||||
// When constructed during transfer the properties get assigned
|
||||
// in the kDeserialize call.
|
||||
if (keyObject) {
|
||||
defineCryptoKeyProperties(
|
||||
this,
|
||||
keyObject,
|
||||
algorithm,
|
||||
extractable,
|
||||
keyUsages,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[kClone]() {
|
||||
const keyObject = this[kKeyObject];
|
||||
const algorithm = this.algorithm;
|
||||
const extractable = this.extractable;
|
||||
const usages = this.usages;
|
||||
const algorithm = this[kAlgorithm];
|
||||
const extractable = this[kExtractable];
|
||||
const usages = this[kKeyUsages];
|
||||
|
||||
return {
|
||||
data: {
|
||||
@@ -742,10 +791,7 @@ class InternalCryptoKey {
|
||||
}
|
||||
|
||||
[kDeserialize]({ keyObject, algorithm, usages, extractable }) {
|
||||
this[kKeyObject] = keyObject;
|
||||
this[kAlgorithm] = algorithm;
|
||||
this[kKeyUsages] = usages;
|
||||
this[kExtractable] = extractable;
|
||||
defineCryptoKeyProperties(this, keyObject, algorithm, extractable, usages);
|
||||
}
|
||||
}
|
||||
InternalCryptoKey.prototype.constructor = CryptoKey;
|
||||
|
||||
Reference in new issue
Block a user