1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async function getEncryptedData(transform)
{
const chunk = await transform.readable.getReader().read();
const value = new Uint8Array(chunk.value);
return [...value];
}
promise_test(async (test) => {
const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
const transform1 = new SFrameTransform;
const transform2 = new SFrameTransform;
const transform3 = new SFrameTransform;
await transform1.setEncryptionKey(key);
await transform2.setEncryptionKey(key);
await transform3.setEncryptionKey(key);
const buffer1 = new ArrayBuffer(10);
const buffer2 = new ArrayBuffer(11);
const view1 = new Uint8Array(buffer1);
const view2 = new Uint8Array(buffer2, 1);
for (let i = 0 ; i < buffer1.byteLength; ++i) {
view1[i] = i;
view2[i] = i;
}
transform1.writable.getWriter().write(buffer1);
transform2.writable.getWriter().write(view1);
transform3.writable.getWriter().write(view2);
const result1 = await getEncryptedData(transform1);
const result2 = await getEncryptedData(transform2);
const result3 = await getEncryptedData(transform3);
assert_array_equals(result1, result2, "result2");
assert_array_equals(result1, result3, "result3");
}, "Uint8Array as input to SFrameTransform");
</script>
</body>
</html>
|