|
|
@@ -27,9 +27,32 @@ function hexdump(buffer) {
|
|
27
|
27
|
const audioBytes = [ 0xde, 0xad, 0xbe, 0xef ];
|
|
28
|
28
|
const videoBytes = [ 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef ];
|
|
29
|
29
|
|
|
|
30
|
+/**
|
|
|
31
|
+ * generates a dummy audio frame
|
|
|
32
|
+ */
|
|
|
33
|
+function makeAudioFrame() {
|
|
|
34
|
+ return {
|
|
|
35
|
+ data: new Uint8Array(audioBytes).buffer,
|
|
|
36
|
+ type: undefined // type is undefined for audio frames.
|
|
|
37
|
+ };
|
|
|
38
|
+}
|
|
|
39
|
+
|
|
|
40
|
+/**
|
|
|
41
|
+ * generates a dummy video frame
|
|
|
42
|
+ */
|
|
|
43
|
+function makeVideoFrame() {
|
|
|
44
|
+ return {
|
|
|
45
|
+ data: new Uint8Array(videoBytes).buffer,
|
|
|
46
|
+ type: 'key'
|
|
|
47
|
+ };
|
|
|
48
|
+}
|
|
|
49
|
+
|
|
|
50
|
+
|
|
30
|
51
|
describe('E2EE Context', () => {
|
|
31
|
52
|
let sender;
|
|
|
53
|
+ let sendController;
|
|
32
|
54
|
let receiver;
|
|
|
55
|
+ let receiveController;
|
|
33
|
56
|
const key = new Uint8Array([
|
|
34
|
57
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
35
|
58
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
@@ -41,8 +64,13 @@ describe('E2EE Context', () => {
|
|
41
|
64
|
});
|
|
42
|
65
|
|
|
43
|
66
|
describe('encode function', () => {
|
|
|
67
|
+ beforeEach(async () => {
|
|
|
68
|
+ await sender.setKey(key, 0);
|
|
|
69
|
+ await receiver.setKey(key, 0);
|
|
|
70
|
+ });
|
|
|
71
|
+
|
|
44
|
72
|
it('with an audio frame', async done => {
|
|
45
|
|
- const sendController = {
|
|
|
73
|
+ sendController = {
|
|
46
|
74
|
enqueue: encodedFrame => {
|
|
47
|
75
|
const data = new Uint8Array(encodedFrame.data);
|
|
48
|
76
|
|
|
|
@@ -50,22 +78,16 @@ describe('E2EE Context', () => {
|
|
50
|
78
|
// 4 bytes truncated signature, counter (1 byte) and 1 byte trailer.
|
|
51
|
79
|
expect(data.byteLength).toEqual(audioBytes.length + 6);
|
|
52
|
80
|
|
|
53
|
|
- // TODO: provide test vector and matcher.
|
|
|
81
|
+ // TODO: provide test vector.
|
|
54
|
82
|
done();
|
|
55
|
83
|
}
|
|
56
|
84
|
};
|
|
57
|
|
- const frame = {
|
|
58
|
|
- data: new Uint8Array(audioBytes).buffer,
|
|
59
|
|
- type: undefined // type is undefined for audio frames.
|
|
60
|
|
- };
|
|
61
|
85
|
|
|
62
|
|
- await sender.setKey(key, 0);
|
|
63
|
|
- await receiver.setKey(key, 0);
|
|
64
|
|
- await sender.encodeFunction(frame, sendController);
|
|
|
86
|
+ await sender.encodeFunction(makeAudioFrame(), sendController);
|
|
65
|
87
|
});
|
|
66
|
88
|
|
|
67
|
89
|
it('with a video frame', async done => {
|
|
68
|
|
- const sendController = {
|
|
|
90
|
+ sendController = {
|
|
69
|
91
|
enqueue: encodedFrame => {
|
|
70
|
92
|
const data = new Uint8Array(encodedFrame.data);
|
|
71
|
93
|
|
|
|
@@ -74,26 +96,28 @@ describe('E2EE Context', () => {
|
|
74
|
96
|
|
|
75
|
97
|
expect(data.byteLength).toEqual(videoBytes.length + 12);
|
|
76
|
98
|
|
|
77
|
|
- // TODO: provide test vector and matcher.
|
|
|
99
|
+ // TODO: provide test vector.
|
|
78
|
100
|
done();
|
|
79
|
101
|
}
|
|
80
|
102
|
};
|
|
81
|
|
- const frame = {
|
|
82
|
|
- data: new Uint8Array(videoBytes).buffer,
|
|
83
|
|
- type: 'key'
|
|
84
|
|
- };
|
|
85
|
103
|
|
|
86
|
|
- await sender.setKey(key, 0);
|
|
87
|
|
- await receiver.setKey(key, 0);
|
|
88
|
|
- await sender.encodeFunction(frame, sendController);
|
|
|
104
|
+ await sender.encodeFunction(makeVideoFrame(), sendController);
|
|
89
|
105
|
});
|
|
90
|
106
|
});
|
|
91
|
107
|
|
|
92
|
108
|
describe('end-to-end test', () => {
|
|
93
|
|
- it('with an audio frame', async done => {
|
|
|
109
|
+ beforeEach(async () => {
|
|
94
|
110
|
await sender.setKey(key, 0);
|
|
95
|
111
|
await receiver.setKey(key, 0);
|
|
96
|
|
- const receiveController = {
|
|
|
112
|
+ sendController = {
|
|
|
113
|
+ enqueue: async encodedFrame => {
|
|
|
114
|
+ await receiver.decodeFunction(encodedFrame, receiveController);
|
|
|
115
|
+ }
|
|
|
116
|
+ };
|
|
|
117
|
+ });
|
|
|
118
|
+
|
|
|
119
|
+ it('with an audio frame', async done => {
|
|
|
120
|
+ receiveController = {
|
|
97
|
121
|
enqueue: encodedFrame => {
|
|
98
|
122
|
const data = new Uint8Array(encodedFrame.data);
|
|
99
|
123
|
|
|
|
@@ -102,23 +126,12 @@ describe('E2EE Context', () => {
|
|
102
|
126
|
done();
|
|
103
|
127
|
}
|
|
104
|
128
|
};
|
|
105
|
|
- const sendController = {
|
|
106
|
|
- enqueue: encodedFrame => {
|
|
107
|
|
- receiver.decodeFunction(encodedFrame, receiveController);
|
|
108
|
|
- }
|
|
109
|
|
- };
|
|
110
|
|
- const frame = {
|
|
111
|
|
- data: new Uint8Array(audioBytes).buffer,
|
|
112
|
|
- type: undefined // type is undefined for audio frames.
|
|
113
|
|
- };
|
|
114
|
129
|
|
|
115
|
|
- await sender.encodeFunction(frame, sendController);
|
|
|
130
|
+ await sender.encodeFunction(makeAudioFrame(), sendController);
|
|
116
|
131
|
});
|
|
117
|
132
|
|
|
118
|
133
|
it('with a video frame', async done => {
|
|
119
|
|
- await sender.setKey(key, 0);
|
|
120
|
|
- await receiver.setKey(key, 0);
|
|
121
|
|
- const receiveController = {
|
|
|
134
|
+ receiveController = {
|
|
122
|
135
|
enqueue: encodedFrame => {
|
|
123
|
136
|
const data = new Uint8Array(encodedFrame.data);
|
|
124
|
137
|
|
|
|
@@ -127,29 +140,17 @@ describe('E2EE Context', () => {
|
|
127
|
140
|
done();
|
|
128
|
141
|
}
|
|
129
|
142
|
};
|
|
130
|
|
- const sendController = {
|
|
131
|
|
- enqueue: encodedFrame => {
|
|
132
|
|
- receiver.decodeFunction(encodedFrame, receiveController);
|
|
133
|
|
- }
|
|
134
|
|
- };
|
|
135
|
|
- const frame = {
|
|
136
|
|
- data: new Uint8Array(videoBytes).buffer,
|
|
137
|
|
- type: 'key'
|
|
138
|
|
- };
|
|
139
|
143
|
|
|
140
|
|
- await sender.encodeFunction(frame, sendController);
|
|
|
144
|
+ await sender.encodeFunction(makeVideoFrame(), sendController);
|
|
141
|
145
|
});
|
|
142
|
146
|
|
|
143
|
147
|
it('the receiver ratchets forward', async done => {
|
|
144
|
|
- await sender.setKey(key, 0);
|
|
145
|
|
- await receiver.setKey(key, 0);
|
|
146
|
|
-
|
|
147
|
148
|
// Ratchet the key. We reimport from the raw bytes.
|
|
148
|
149
|
const material = await importKey(key);
|
|
149
|
150
|
|
|
150
|
151
|
await sender.setKey(await ratchet(material), 0);
|
|
151
|
152
|
|
|
152
|
|
- const receiveController = {
|
|
|
153
|
+ receiveController = {
|
|
153
|
154
|
enqueue: encodedFrame => {
|
|
154
|
155
|
const data = new Uint8Array(encodedFrame.data);
|
|
155
|
156
|
|
|
|
@@ -158,17 +159,8 @@ describe('E2EE Context', () => {
|
|
158
|
159
|
done();
|
|
159
|
160
|
}
|
|
160
|
161
|
};
|
|
161
|
|
- const sendController = {
|
|
162
|
|
- enqueue: encodedFrame => {
|
|
163
|
|
- receiver.decodeFunction(encodedFrame, receiveController);
|
|
164
|
|
- }
|
|
165
|
|
- };
|
|
166
|
|
- const frame = {
|
|
167
|
|
- data: new Uint8Array(audioBytes).buffer,
|
|
168
|
|
- type: undefined
|
|
169
|
|
- };
|
|
170
|
162
|
|
|
171
|
|
- await sender.encodeFunction(frame, sendController);
|
|
|
163
|
+ await sender.encodeFunction(makeAudioFrame(), sendController);
|
|
172
|
164
|
});
|
|
173
|
165
|
});
|
|
174
|
166
|
});
|