|
| 1 | +// META: title=WebCryptoAPI: BufferSource arguments and members reject shared buffers |
| 2 | + |
| 3 | +// None of the BufferSource arguments of SubtleCrypto, or of the dictionaries it |
| 4 | +// takes, are [AllowShared], so a SharedArrayBuffer, or a view onto one, has to |
| 5 | +// throw a TypeError. |
| 6 | +// |
| 7 | +// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`. |
| 8 | +const sharedBuffer = new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 }).buffer; |
| 9 | + |
| 10 | +function generateAesGcmKey() { |
| 11 | + return crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, false, ["encrypt"]); |
| 12 | +} |
| 13 | + |
| 14 | +for (const [kind, buffer] of [["SharedArrayBuffer", sharedBuffer], |
| 15 | + ["Uint8Array(SharedArrayBuffer)", new Uint8Array(sharedBuffer)]]) { |
| 16 | + promise_test(t => { |
| 17 | + return promise_rejects_js(t, TypeError, crypto.subtle.digest("SHA-256", buffer)); |
| 18 | + }, `digest() data is a ${kind}`); |
| 19 | + |
| 20 | + promise_test(async t => { |
| 21 | + const key = await generateAesGcmKey(); |
| 22 | + await promise_rejects_js(t, TypeError, |
| 23 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, buffer)); |
| 24 | + }, `encrypt() data is a ${kind}`); |
| 25 | + |
| 26 | + promise_test(async t => { |
| 27 | + const key = await generateAesGcmKey(); |
| 28 | + await promise_rejects_js(t, TypeError, |
| 29 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: buffer }, key, new Uint8Array(1))); |
| 30 | + }, `encrypt() AesGcmParams.iv is a ${kind}`); |
| 31 | + |
| 32 | + promise_test(async t => { |
| 33 | + const key = await generateAesGcmKey(); |
| 34 | + await promise_rejects_js(t, TypeError, |
| 35 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12), additionalData: buffer }, |
| 36 | + key, new Uint8Array(1))); |
| 37 | + }, `encrypt() AesGcmParams.additionalData is a ${kind}`); |
| 38 | +} |
0 commit comments