2013-05-15 07:11:08 -04:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// import web worker dependencies
|
2013-06-10 18:55:53 -04:00
|
|
|
importScripts('../../lib/require.js');
|
2013-05-15 07:11:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2013-06-10 18:55:53 -04:00
|
|
|
// fetch dependencies via require.js
|
|
|
|
require(['../../require-config'], function() {
|
|
|
|
require.config({
|
|
|
|
baseUrl: '../../lib'
|
|
|
|
});
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-06-10 18:55:53 -04:00
|
|
|
require(['cryptoLib/crypto-batch'], function(batch) {
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-06-10 18:55:53 -04:00
|
|
|
var i = e.data,
|
|
|
|
output = null;
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-06-10 18:55:53 -04:00
|
|
|
if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) {
|
|
|
|
// start encryption
|
|
|
|
output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-06-10 18:55:53 -04:00
|
|
|
} else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) {
|
|
|
|
// start decryption
|
|
|
|
output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey);
|
2013-05-15 07:11:08 -04:00
|
|
|
|
2013-06-26 11:37:21 -04:00
|
|
|
} else if (i.type === 'reencrypt' && i.senderPubkeys && i.receiverPrivkey && i.list && i.symKey) {
|
|
|
|
// start validation and re-encryption
|
|
|
|
output = batch.reencryptListKeysForUser(i.list, i.senderPubkeys, i.receiverPrivkey, i.symKey);
|
|
|
|
|
|
|
|
} else if (i.type === 'decryptItems' && i.symKey && i.list) {
|
|
|
|
// start decryption
|
|
|
|
output = batch.decryptKeysAndList(i.list, i.symKey);
|
|
|
|
|
2013-06-10 18:55:53 -04:00
|
|
|
} else {
|
|
|
|
throw 'Not all arguments for web worker crypto are defined!';
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass output back to main thread
|
|
|
|
self.postMessage(output);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2013-05-15 07:11:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}());
|