Skip to content

Commit

Permalink
crypto: remove non-standard webcrypto.Crypto.prototype.CryptoKey
Browse files Browse the repository at this point in the history
`CryptoKey` is already available on the global object.

PR-URL: #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>
  • Loading branch information
aduh95 committed Sep 17, 2022
1 parent 6de2673 commit 2849283
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions lib/internal/crypto/webcrypto.js
Expand Up @@ -5,6 +5,7 @@ const {
JSONParse,
JSONStringify,
ObjectDefineProperties,
ObjectDefineProperty,
ReflectApply,
ReflectConstruct,
SafeSet,
Expand All @@ -28,6 +29,10 @@ const {
validateString,
} = require('internal/validators');

const {
getOptionValue,
} = require('internal/options');

const { TextDecoder, TextEncoder } = require('internal/encoding');

const {
Expand Down Expand Up @@ -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]: {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-subtle-zero-length.js
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-webcrypto-keygen.js
Expand Up @@ -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');
Expand Down

0 comments on commit 2849283

Please sign in to comment.