diff options
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r-- | ext/crypto/00_crypto.js | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index 5a42efbfd..aa328d1d7 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -15,20 +15,18 @@ const { TextEncoder, TextDecoder } = window.__bootstrap.encoding; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypeEvery, ArrayPrototypeFind, ArrayPrototypeIncludes, - BigInt64ArrayPrototype, - BigUint64ArrayPrototype, - Int16ArrayPrototype, - Int32ArrayPrototype, - Int8ArrayPrototype, + BigInt64Array, + Int16Array, + Int32Array, + Int8Array, JSONParse, JSONStringify, ObjectAssign, - ObjectPrototypeIsPrototypeOf, StringPrototypeToLowerCase, StringPrototypeToUpperCase, Symbol, @@ -36,11 +34,10 @@ SyntaxError, TypedArrayPrototypeSlice, TypeError, - Uint16ArrayPrototype, - Uint32ArrayPrototype, + Uint16Array, + Uint32Array, Uint8Array, - Uint8ArrayPrototype, - Uint8ClampedArrayPrototype, + Uint8ClampedArray, WeakMap, WeakMapPrototypeGet, WeakMapPrototypeSet, @@ -289,26 +286,26 @@ /** @returns {string} */ get type() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); return this[_type]; } /** @returns {boolean} */ get extractable() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); return this[_extractable]; } /** @returns {string[]} */ get usages() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); // TODO(lucacasonato): return a SameObject copy return this[_usages]; } /** @returns {object} */ get algorithm() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); // TODO(lucacasonato): return a SameObject copy return this[_algorithm]; } @@ -326,7 +323,6 @@ } webidl.configurePrototype(CryptoKey); - const CryptoKeyPrototype = CryptoKey.prototype; /** * @param {string} type @@ -433,7 +429,7 @@ * @returns {Promise<Uint8Array>} */ async digest(algorithm, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'digest' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 2, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -465,7 +461,7 @@ * @returns {Promise<any>} */ async encrypt(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'encrypt' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -513,7 +509,7 @@ * @returns {Promise<any>} */ async decrypt(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'decrypt' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -709,7 +705,7 @@ * @returns {Promise<any>} */ async sign(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'sign' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -841,7 +837,7 @@ */ // deno-lint-ignore require-await async importKey(format, keyData, algorithm, extractable, keyUsages) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -867,19 +863,13 @@ // 2. if (format !== "jwk") { - if ( - ArrayBufferIsView(keyData) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, keyData) - ) { + if (ArrayBufferIsView(keyData) || keyData instanceof ArrayBuffer) { keyData = copyBuffer(keyData); } else { throw new TypeError("keyData is a JsonWebKey"); } } else { - if ( - ArrayBufferIsView(keyData) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, keyData) - ) { + if (ArrayBufferIsView(keyData) || keyData instanceof ArrayBuffer) { throw new TypeError("keyData is not a JsonWebKey"); } } @@ -959,7 +949,7 @@ */ // deno-lint-ignore require-await async exportKey(format, key) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'exportKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 2, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1009,7 +999,7 @@ * @returns {Promise<ArrayBuffer>} */ async deriveBits(algorithm, baseKey, length) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'deriveBits' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1057,7 +1047,7 @@ extractable, keyUsages, ) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'deriveKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 5, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1152,7 +1142,7 @@ * @returns {Promise<boolean>} */ async verify(algorithm, key, signature, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'verify' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1273,7 +1263,7 @@ * @returns {Promise<any>} */ async wrapKey(format, key, wrappingKey, wrapAlgorithm) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'wrapKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1406,7 +1396,7 @@ extractable, keyUsages, ) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'unwrapKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 7, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1564,7 +1554,7 @@ * @returns {Promise<any>} */ async generateKey(algorithm, extractable, keyUsages) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'generateKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1590,14 +1580,12 @@ usages, ); - if (ObjectPrototypeIsPrototypeOf(CryptoKeyPrototype, result)) { + if (result instanceof CryptoKey) { const type = result[_type]; if ((type === "secret" || type === "private") && usages.length === 0) { throw new DOMException("Invalid key usages", "SyntaxError"); } - } else if ( - ObjectPrototypeIsPrototypeOf(CryptoKeyPrototype, result.privateKey) - ) { + } else if (result.privateKey instanceof CryptoKey) { if (result.privateKey[_usages].length === 0) { throw new DOMException("Invalid key usages", "SyntaxError"); } @@ -1606,7 +1594,6 @@ return result; } } - const SubtleCryptoPrototype = SubtleCrypto.prototype; async function generateKey(normalizedAlgorithm, extractable, usages) { const algorithmName = normalizedAlgorithm.name; @@ -3839,7 +3826,7 @@ } getRandomValues(arrayBufferView) { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); const prefix = "Failed to execute 'getRandomValues' on 'Crypto'"; webidl.requiredArguments(arguments.length, 1, { prefix }); arrayBufferView = webidl.converters.ArrayBufferView(arrayBufferView, { @@ -3848,21 +3835,15 @@ }); if ( !( - ObjectPrototypeIsPrototypeOf(Int8ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf( - Uint8ClampedArrayPrototype, - arrayBufferView, - ) || - ObjectPrototypeIsPrototypeOf(Int16ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint16ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Int32ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint32ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf( - BigInt64ArrayPrototype, - arrayBufferView, - ) || - ObjectPrototypeIsPrototypeOf(BigUint64ArrayPrototype, arrayBufferView) + arrayBufferView instanceof Int8Array || + arrayBufferView instanceof Uint8Array || + arrayBufferView instanceof Uint8ClampedArray || + arrayBufferView instanceof Int16Array || + arrayBufferView instanceof Uint16Array || + arrayBufferView instanceof Int32Array || + arrayBufferView instanceof Uint32Array || + arrayBufferView instanceof BigInt64Array || + arrayBufferView instanceof BigUint64Array ) ) { throw new DOMException( @@ -3880,12 +3861,12 @@ } randomUUID() { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); return core.opSync("op_crypto_random_uuid"); } get subtle() { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); return subtle; } @@ -3895,7 +3876,6 @@ } webidl.configurePrototype(Crypto); - const CryptoPrototype = Crypto.prototype; window.__bootstrap.crypto = { SubtleCrypto, |