mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
web worker tests work again
This commit is contained in:
parent
0e9be73791
commit
1368672c1d
@ -51,6 +51,7 @@ module.exports = function(grunt) {
|
||||
qunit: {
|
||||
all: {
|
||||
options: {
|
||||
timeout: 20000,
|
||||
urls: [
|
||||
'http://localhost:<%= connect.test.options.port %>/test/unit/index.html',
|
||||
'http://localhost:<%= connect.test.options.port %>/test/integration/index.html'
|
||||
|
@ -2,36 +2,41 @@
|
||||
'use strict';
|
||||
|
||||
// import web worker dependencies
|
||||
importScripts('../../lib/forge/forge.rsa.bundle.js');
|
||||
importScripts('../app-config.js');
|
||||
importScripts('./crypto-batch.js');
|
||||
importScripts('./aes-cbc.js');
|
||||
importScripts('../../lib/require.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) {
|
||||
// fetch dependencies via require.js
|
||||
require(['../../require-config'], function() {
|
||||
require.config({
|
||||
baseUrl: '../../lib'
|
||||
});
|
||||
|
||||
var i = e.data,
|
||||
output = null,
|
||||
aes = new cryptoLib.AesCBC(forge),
|
||||
batch = new cryptoLib.CryptoBatch(aes);
|
||||
require(['cryptoLib/crypto-batch'], function(batch) {
|
||||
|
||||
if (i.type === 'encrypt' && i.list) {
|
||||
// start encryption
|
||||
output = batch.encryptList(i.list);
|
||||
var i = e.data,
|
||||
output = null;
|
||||
|
||||
} else if (i.type === 'decrypt' && i.list) {
|
||||
// start decryption
|
||||
output = batch.decryptList(i.list);
|
||||
if (i.type === 'encrypt' && i.list) {
|
||||
// start encryption
|
||||
output = batch.encryptList(i.list);
|
||||
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
} else if (i.type === 'decrypt' && i.list) {
|
||||
// start decryption
|
||||
output = batch.decryptList(i.list);
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
@ -2,34 +2,41 @@
|
||||
'use strict';
|
||||
|
||||
// import web worker dependencies
|
||||
importScripts('../../lib/forge/forge.rsa.bundle.js');
|
||||
importScripts('../app-config.js');
|
||||
importScripts('./aes-cbc.js');
|
||||
importScripts('../../lib/require.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) {
|
||||
// fetch dependencies via require.js
|
||||
require(['../../require-config'], function() {
|
||||
require.config({
|
||||
baseUrl: '../../lib'
|
||||
});
|
||||
|
||||
var i = e.data,
|
||||
output = null,
|
||||
aes = new cryptoLib.AesCBC(forge);
|
||||
require(['cryptoLib/aes-cbc'], function(aes) {
|
||||
|
||||
if (i.type === 'encrypt' && i.plaintext && i.key && i.iv) {
|
||||
// start encryption
|
||||
output = aes.encrypt(i.plaintext, i.key, i.iv);
|
||||
var i = e.data,
|
||||
output = null;
|
||||
|
||||
} else if (i.type === 'decrypt' && i.ciphertext && i.key && i.iv) {
|
||||
// start decryption
|
||||
output = aes.decrypt(i.ciphertext, i.key, i.iv);
|
||||
if (i.type === 'encrypt' && i.plaintext && i.key && i.iv) {
|
||||
// start encryption
|
||||
output = aes.encrypt(i.plaintext, i.key, i.iv);
|
||||
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
} else if (i.type === 'decrypt' && i.ciphertext && i.key && i.iv) {
|
||||
// start decryption
|
||||
output = aes.decrypt(i.ciphertext, i.key, i.iv);
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
@ -2,41 +2,41 @@
|
||||
'use strict';
|
||||
|
||||
// import web worker dependencies
|
||||
importScripts('../../lib/underscore-1.4.4.min.js');
|
||||
importScripts('../../lib/forge/forge.rsa.bundle.js');
|
||||
importScripts('../app-config.js');
|
||||
importScripts('./crypto-batch.js');
|
||||
importScripts('./aes-cbc.js');
|
||||
importScripts('./util.js');
|
||||
importScripts('./rsa.js');
|
||||
importScripts('../../lib/require.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) {
|
||||
// fetch dependencies via require.js
|
||||
require(['../../require-config'], function() {
|
||||
require.config({
|
||||
baseUrl: '../../lib'
|
||||
});
|
||||
|
||||
var i = e.data,
|
||||
output = null,
|
||||
aes = new cryptoLib.AesCBC(forge),
|
||||
rsa = new cryptoLib.RSA(forge),
|
||||
util = new cryptoLib.Util(),
|
||||
batch = new cryptoLib.CryptoBatch(aes, rsa, util, _);
|
||||
require(['cryptoLib/crypto-batch'], function(batch) {
|
||||
|
||||
if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) {
|
||||
// start encryption
|
||||
output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey);
|
||||
var i = e.data,
|
||||
output = null;
|
||||
|
||||
} else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) {
|
||||
// start decryption
|
||||
output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey);
|
||||
if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) {
|
||||
// start encryption
|
||||
output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey);
|
||||
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
} else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) {
|
||||
// start decryption
|
||||
output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey);
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(output);
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
@ -2,7 +2,9 @@
|
||||
* High level crypto api that invokes native crypto (if available) and
|
||||
* gracefully degrades to JS crypto (if unavailable)
|
||||
*/
|
||||
define(['cryptoLib/util', 'cryptoLib/aes-cbc', 'cryptoLib/rsa', 'cryptoLib/crypto-batch', 'js/crypto/pbkdf2'], function(util, aes, rsa, cryptoBatch, pbkdf2) {
|
||||
define(['cryptoLib/util', 'cryptoLib/aes-cbc', 'cryptoLib/rsa', 'cryptoLib/crypto-batch',
|
||||
'js/crypto/pbkdf2'
|
||||
], function(util, aes, rsa, cryptoBatch, pbkdf2) {
|
||||
'use strict';
|
||||
|
||||
var self = {};
|
||||
|
@ -2,30 +2,37 @@
|
||||
'use strict';
|
||||
|
||||
// import web worker dependencies
|
||||
importScripts('../../lib/forge/forge.rsa.bundle.js');
|
||||
importScripts('../app-config.js');
|
||||
importScripts('./pbkdf2.js');
|
||||
importScripts('../../lib/require.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) {
|
||||
// fetch dependencies via require.js
|
||||
require(['../../require-config'], function() {
|
||||
require.config({
|
||||
baseUrl: '../../lib'
|
||||
});
|
||||
|
||||
var i = e.data,
|
||||
key = null;
|
||||
require(['js/crypto/pbkdf2'], function(pbkdf2) {
|
||||
|
||||
if (i.password && i.keySize) {
|
||||
// start deriving key
|
||||
var pbkdf2 = new app.crypto.PBKDF2();
|
||||
key = pbkdf2.getKey(i.password, i.keySize);
|
||||
var i = e.data,
|
||||
key = null;
|
||||
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
if (i.password && i.keySize) {
|
||||
// start deriving key
|
||||
key = pbkdf2.getKey(i.password, i.keySize);
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(key);
|
||||
} else {
|
||||
throw 'Not all arguments for web worker crypto are defined!';
|
||||
}
|
||||
|
||||
// pass output back to main thread
|
||||
self.postMessage(key);
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
@ -13,7 +13,6 @@ require(['../../src/require-config'], function() {
|
||||
window.Worker = undefined;
|
||||
|
||||
app.config.workerPath = '../../src/js';
|
||||
app.config.cloudUrl = 'http://localhost:8888';
|
||||
|
||||
startTests();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user