1 | import window from 'global/window';
|
2 | import {Decrypter} from 'aes-decrypter';
|
3 | import { createTransferableMessage } from './bin-utils';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const DecrypterWorker = function(self) {
|
14 | self.onmessage = function(event) {
|
15 | const data = event.data;
|
16 | const encrypted = new Uint8Array(data.encrypted.bytes,
|
17 | data.encrypted.byteOffset,
|
18 | data.encrypted.byteLength);
|
19 | const key = new Uint32Array(data.key.bytes,
|
20 | data.key.byteOffset,
|
21 | data.key.byteLength / 4);
|
22 | const iv = new Uint32Array(data.iv.bytes,
|
23 | data.iv.byteOffset,
|
24 | data.iv.byteLength / 4);
|
25 |
|
26 |
|
27 | new Decrypter(encrypted,
|
28 | key,
|
29 | iv,
|
30 | function(err, bytes) {
|
31 | window.postMessage(createTransferableMessage({
|
32 | source: data.source,
|
33 | decrypted: bytes
|
34 | }), [bytes.buffer]);
|
35 | });
|
36 |
|
37 | };
|
38 | };
|
39 |
|
40 | export default (self) => {
|
41 | return new DecrypterWorker(self);
|
42 | };
|