diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-02-24 14:19:36 +0300 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-09-17 16:54:36 +0300 |
commit | 2849283c4cebbfbf523cc24303941dc36df9332f (patch) | |
tree | 911acb3a50d7870d98c270a13631966c569bdc62 | |
parent | 6de2673a9f9420e87066422375278d0156079889 (diff) |
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>
-rw-r--r-- | lib/internal/crypto/webcrypto.js | 24 | ||||
-rw-r--r-- | test/parallel/test-crypto-subtle-zero-length.js | 2 | ||||
-rw-r--r-- | test/parallel/test-webcrypto-keygen.js | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index df4bb072043..736137d406b 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -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]: { diff --git a/test/parallel/test-crypto-subtle-zero-length.js b/test/parallel/test-crypto-subtle-zero-length.js index ffca84cf561..544374b7482 100644 --- a/test/parallel/test-crypto-subtle-zero-length.js +++ b/test/parallel/test-crypto-subtle-zero-length.js @@ -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', diff --git a/test/parallel/test-webcrypto-keygen.js b/test/parallel/test-webcrypto-keygen.js index 5acea2debdd..7d266e601b7 100644 --- a/test/parallel/test-webcrypto-keygen.js +++ b/test/parallel/test-webcrypto-keygen.js @@ -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'); |