UNPKG

1.47 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
8
9var _globalWindow = require('global/window');
10
11var _globalWindow2 = _interopRequireDefault(_globalWindow);
12
13var _aesDecrypter = require('aes-decrypter');
14
15var _binUtils = require('./bin-utils');
16
17/**
18 * Our web worker interface so that things can talk to aes-decrypter
19 * that will be running in a web worker. the scope is passed to this by
20 * webworkify.
21 *
22 * @param {Object} self
23 * the scope for the web worker
24 */
25var DecrypterWorker = function DecrypterWorker(self) {
26 self.onmessage = function (event) {
27 var data = event.data;
28 var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
29 var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
30 var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
31
32 /* eslint-disable no-new, handle-callback-err */
33 new _aesDecrypter.Decrypter(encrypted, key, iv, function (err, bytes) {
34 _globalWindow2['default'].postMessage((0, _binUtils.createTransferableMessage)({
35 source: data.source,
36 decrypted: bytes
37 }), [bytes.buffer]);
38 });
39 /* eslint-enable */
40 };
41};
42
43exports['default'] = function (self) {
44 return new DecrypterWorker(self);
45};
46
47module.exports = exports['default'];
\No newline at end of file