1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-04 16:25:07 -05:00
mail/src/js/crypto/aes-worker.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
// import web worker dependencies
importScripts('../../lib/sjcl/sjcl.js');
importScripts('../../lib/sjcl/bitArray.js');
importScripts('../../lib/sjcl/codecBase64.js');
importScripts('../../lib/sjcl/codecString.js');
importScripts('../../lib/sjcl/aes.js');
importScripts('../../lib/sjcl/ccm.js');
importScripts('../app-config.js');
importScripts('./aes-ccm.js');
2013-03-13 11:58:46 -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.addEventListener('message', function(e) {
2013-03-13 11:58:46 -04:00
var args = e.data,
output = null,
aes = new app.crypto.AesCCM();
2013-03-13 11:58:46 -04:00
if (args.type === 'encrypt' && args.plaintext && args.key && args.iv) {
// start encryption
output = aes.encrypt(args.plaintext, args.key, args.iv);
2013-03-13 11:58:46 -04:00
} else if (args.type === 'decrypt' && args.ciphertext && args.key && args.iv) {
// start decryption
output = aes.decrypt(args.ciphertext, args.key, args.iv);
2013-03-13 11:58:46 -04:00
} else {
throw 'Not all arguments for web worker crypto are defined!';
}
2013-03-13 11:58:46 -04:00
// pass output back to main thread
self.postMessage(output);
}, false);
2013-03-13 11:58:46 -04:00
}());