2013-05-15 07:11:08 -04:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// import web worker dependencies
|
|
|
|
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,
|
|
|
|
aes = new app.crypto.AesCBC(forge),
|
2013-05-15 07:36:59 -04:00
|
|
|
rsa = new app.crypto.RSA(forge),
|
2013-05-15 08:14:08 -04:00
|
|
|
util = new app.crypto.Util(),
|
|
|
|
batch = new app.crypto.CryptoBatch(aes, rsa, util);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-05-15 07:36:59 -04:00
|
|
|
// pass RSA keys to module
|
2013-05-15 07:11:08 -04:00
|
|
|
rsa.init(i.pubkeyPem, i.privkeyPem);
|
|
|
|
|
|
|
|
if (i.type === 'encrypt' && i.list) {
|
|
|
|
// start encryption
|
2013-05-15 07:36:59 -04:00
|
|
|
output = batch.encryptListForUser(i.list);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
|
|
|
} else if (i.type === 'decrypt' && i.list) {
|
|
|
|
// start decryption
|
2013-05-15 07:36:59 -04:00
|
|
|
output = batch.decryptListForUser(i.list);
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|