forked from mallocnode/WebClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openpgp.worker.min.js
1 lines (1 loc) · 4.98 KB
/
openpgp.worker.min.js
1
/*! OpenPGPjs.org this is LGPL licensed code, see LICENSE/our website for more information.- v0.11.0-PM - 2015-04-21 */!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a){window.openpgp.crypto.random.randomBuffer.size<g&&postMessage({event:"request-seed"}),postMessage(a)}function e(a){var b=window.openpgp.packet.List.fromStructuredClone(a);return new window.openpgp.key.Key(b)}function f(a){var b=window.openpgp.packet.List.fromStructuredClone(a);return new window.openpgp.message.Message(b)}window={},Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),importScripts("openpgp.min.js");var g=4e4,h=6e4;window.openpgp.crypto.random.randomBuffer.init(h),self.onmessage=function(a){var b=null,c=null,g=a.data,h=!1;switch(g.event){case"configure":for(var i in g.config)window.openpgp.config[i]=g.config[i];break;case"seed-random":g.buf instanceof Uint8Array||(g.buf=new Uint8Array(g.buf)),window.openpgp.crypto.random.randomBuffer.set(g.buf);break;case"encrypt-message":g.keys&&(g.keys=g.keys.map(e)),window.openpgp.encryptMessage(g.keys,g.data,g.passwords,g.params).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"encrypt-session-key":g.keys&&(g.keys=g.keys.map(e)),window.openpgp.encryptSessionKey(g.sessionKey,g.algo,g.keys,g.passwords).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"sign-and-encrypt-message":g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(e),g.privateKey=e(g.privateKey),window.openpgp.signAndEncryptMessage(g.publicKeys,g.privateKey,g.text).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"decrypt-message":String.prototype.isPrototypeOf(g.privateKey)||"string"==typeof g.privateKey||Uint8Array.prototype.isPrototypeOf(g.privateKey)||(g.privateKey=e(g.privateKey)),g.message=f(g.message.packets),window.openpgp.decryptMessage(g.privateKey,g.message,g.params).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"decrypt-session-key":String.prototype.isPrototypeOf(g.privateKey)||"string"==typeof g.privateKey||(g.privateKey=e(g.privateKey)),g.message=f(g.message.packets),window.openpgp.decryptSessionKey(g.privateKey,g.message).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"decrypt-and-verify-message":g.privateKey=e(g.privateKey),g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(e),g.message=f(g.message.packets),window.openpgp.decryptAndVerifyMessage(g.privateKey,g.publicKeys,g.message).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"sign-clear-message":g.privateKeys=g.privateKeys.map(e),window.openpgp.signClearMessage(g.privateKeys,g.text).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"verify-clear-signed-message":g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(e);var j=window.openpgp.packet.List.fromStructuredClone(g.message.packets);g.message=new window.openpgp.cleartext.CleartextMessage(g.message.text,j),window.openpgp.verifyClearSignedMessage(g.publicKeys,g.message).then(function(a){d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"generate-key-pair":window.openpgp.generateKeyPair(g.options).then(function(a){a.key=a.key.toPacketlist(),d({event:"method-return",data:a})})["catch"](function(a){d({event:"method-return",err:a.message})});break;case"decrypt-key":try{g.privateKey=e(g.privateKey),h=g.privateKey.decrypt(g.password),h?b=g.privateKey.toPacketlist():c="Wrong password"}catch(k){c=k.message}d({event:"method-return",data:b,err:c});break;case"decrypt-key-packet":try{g.privateKey=e(g.privateKey),g.keyIds=g.keyIds.map(window.openpgp.Keyid.fromClone),h=g.privateKey.decryptKeyPacket(g.keyIds,g.password),h?b=g.privateKey.toPacketlist():c="Wrong password"}catch(k){c=k.message}d({event:"method-return",data:b,err:c});break;default:throw new Error("Unknown Worker Event.")}}},{}]},{},[1]);