crypto: remove non-standard webcrypto.Crypto.prototype.CryptoKey

`CryptoKey` is already available on the global object.

PR-URL: https://github.com/nodejs/node/pull/42083
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Antoine du Hamel 2022-02-24 12:19:36 +01:00
parent 6de2673a9f
commit 2849283c4c
3 changed files with 19 additions and 9 deletions

View File

@ -5,6 +5,7 @@ const {
JSONParse,
JSONStringify,
ObjectDefineProperties,
ObjectDefineProperty,
ReflectApply,
ReflectConstruct,
SafeSet,
@ -28,6 +29,10 @@ const {
validateString,
} = require('internal/validators');
const {
getOptionValue,
} = require('internal/options');
const { TextDecoder, TextEncoder } = require('internal/encoding');
const {
@ -792,15 +797,20 @@ ObjectDefineProperties(
writable: true,
value: randomUUID,
},
CryptoKey: {
__proto__: null,
enumerable: true,
configurable: true,
writable: true,
value: CryptoKey,
}
});
if (getOptionValue('--no-experimental-global-webcrypto')) {
// For backward compatibility, keep exposing CryptoKey in the Crypto prototype
// when using the flag.
ObjectDefineProperty(Crypto.prototype, 'CryptoKey', {
__proto__: null,
enumerable: true,
configurable: true,
writable: true,
value: CryptoKey,
});
}
ObjectDefineProperties(
SubtleCrypto.prototype, {
[SymbolToStringTag]: {

View File

@ -15,7 +15,7 @@ const crypto = require('crypto').webcrypto;
{ name: 'AES-GCM' },
false,
[ 'encrypt', 'decrypt' ]);
assert(k instanceof crypto.CryptoKey);
assert(k instanceof CryptoKey);
const e = await crypto.subtle.encrypt({
name: 'AES-GCM',

View File

@ -9,7 +9,7 @@ if (!common.hasCrypto)
const assert = require('assert');
const { types: { isCryptoKey } } = require('util');
const {
webcrypto: { subtle, CryptoKey },
webcrypto: { subtle },
createSecretKey,
KeyObject,
} = require('crypto');