Set config in AsyncProxy

This commit is contained in:
Tankred Hase 2015-02-11 14:01:08 +01:00
parent c9e019d20e
commit da3dbf7acc
5 changed files with 10 additions and 8 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "openpgp", "name": "openpgp",
"description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.", "description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
"version": "0.9.0", "version": "0.10.0",
"homepage": "http://openpgpjs.org/", "homepage": "http://openpgpjs.org/",
"engines": { "engines": {
"node": ">=0.8" "node": ">=0.8"

View File

@ -56,8 +56,9 @@ var asyncProxy = null; // instance of the asyncproxy
* @return {Boolean} true if worker created successfully * @return {Boolean} true if worker created successfully
*/ */
function initWorker(path, options) { function initWorker(path, options) {
if (options && options.worker || if (options && options.worker || typeof window !== 'undefined' && window.Worker) {
typeof window !== 'undefined' && window.Worker) { options = options || {};
options.config = this.config;
asyncProxy = new AsyncProxy(path, options); asyncProxy = new AsyncProxy(path, options);
return true; return true;
} else { } else {

View File

@ -38,6 +38,7 @@ var INITIAL_RANDOM_SEED = 50000, // random bytes seeded to worker
* Initializes a new proxy and loads the web worker * Initializes a new proxy and loads the web worker
* @constructor * @constructor
* @param {String} path The path to the worker or 'openpgp.worker.js' by default * @param {String} path The path to the worker or 'openpgp.worker.js' by default
* @param {Object} [options.config=Object] config The worker configuration
* @param {Object} [options.worker=Object] alternative to path parameter: * @param {Object} [options.worker=Object] alternative to path parameter:
* web worker initialized with 'openpgp.worker.js' * web worker initialized with 'openpgp.worker.js'
*/ */
@ -54,7 +55,7 @@ function AsyncProxy(path, options) {
this.seedRandom(INITIAL_RANDOM_SEED); this.seedRandom(INITIAL_RANDOM_SEED);
// FIFO // FIFO
this.tasks = []; this.tasks = [];
this.worker.postMessage({event: 'configure', config: config}); this.worker.postMessage({event: 'configure', config: options.config});
} }
/** /**

View File

@ -54,10 +54,10 @@ self.onmessage = function (event) {
switch (msg.event) { switch (msg.event) {
case 'configure': case 'configure':
for(var i in msg.config){ for (var i in msg.config) {
window.openpgp.config[i] = msg.config[i]; window.openpgp.config[i] = msg.config[i];
} }
break; break;
case 'seed-random': case 'seed-random':
if (!(msg.buf instanceof Uint8Array)) { if (!(msg.buf instanceof Uint8Array)) {
msg.buf = new Uint8Array(msg.buf); msg.buf = new Uint8Array(msg.buf);

View File

@ -202,13 +202,13 @@ describe('High level API', function() {
describe('Main', function(){ describe('Main', function(){
it('Configuration', function(done){ it('Configuration', function(done){
openpgp.config.show_comment = false;
openpgp.config.show_version = false; openpgp.config.show_version = false;
openpgp.config.commentstring = 'different';
openpgp.initWorker('../dist/openpgp.worker.js'); openpgp.initWorker('../dist/openpgp.worker.js');
openpgp.encryptMessage([pubKeyRSA], plaintext).then(function(data) { openpgp.encryptMessage([pubKeyRSA], plaintext).then(function(data) {
expect(data).to.exist; expect(data).to.exist;
expect(data).not.to.match(/^Version:/); expect(data).not.to.match(/^Version:/);
expect(data).not.to.match(/^Comment:/); expect(data).to.match(/Comment: different/);
done(); done();
}); });
}); });