2013-05-15 07:11:08 -04:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// import web worker dependencies
|
2013-05-23 16:17:25 -04:00
|
|
|
importScripts('../../lib/underscore-1.4.4.min.js');
|
2013-05-15 07:11:08 -04:00
|
|
|
importScripts('../../lib/forge/forge.rsa.bundle.js');
|
|
|
|
importScripts('../app-config.js');
|
2013-05-15 07:36:59 -04:00
|
|
|
importScripts('./crypto-batch.js');
|
2013-05-15 07:11:08 -04:00
|
|
|
importScripts('./aes-cbc.js');
|
2013-05-15 08:14:08 -04:00
|
|
|
importScripts('./util.js');
|
2013-05-15 07:11:08 -04:00
|
|
|
importScripts('./rsa.js');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In the web worker thread context, 'this' and 'self' can be used as a global
|
|
|
|
* variable namespace similar to the 'window' object in the main thread
|
|
|
|
*/
|
|
|
|
self.onmessage = function(e) {
|
|
|
|
|
|
|
|
var i = e.data,
|
|
|
|
output = null,
|
2013-05-22 11:03:54 -04:00
|
|
|
aes = new cryptoLib.AesCBC(forge),
|
|
|
|
rsa = new cryptoLib.RSA(forge),
|
|
|
|
util = new cryptoLib.Util(),
|
2013-05-23 16:17:25 -04:00
|
|
|
batch = new cryptoLib.CryptoBatch(aes, rsa, util, _);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-05-23 16:17:25 -04:00
|
|
|
if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) {
|
2013-05-15 07:11:08 -04:00
|
|
|
// start encryption
|
2013-05-23 16:17:25 -04:00
|
|
|
output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-05-23 16:17:25 -04:00
|
|
|
} else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) {
|
2013-05-15 07:11:08 -04:00
|
|
|
// start decryption
|
2013-05-23 16:17:25 -04:00
|
|
|
output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
throw 'Not all arguments for web worker crypto are defined!';
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass output back to main thread
|
|
|
|
self.postMessage(output);
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|