mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-07 17:41:33 +00:00
Remove worker (#1072)
This commit is contained in:
@@ -339,21 +339,4 @@ tryTests('Brainpool Omnibus Tests @lightweight', omnibus, {
|
||||
if: !openpgp.config.ci && (openpgp.config.use_indutny_elliptic || openpgp.util.getNodeCrypto())
|
||||
});
|
||||
|
||||
tryTests('Brainpool Omnibus Tests - Worker @lightweight', omnibus, {
|
||||
if: typeof window !== 'undefined' && window.Worker && (openpgp.config.use_indutny_elliptic || openpgp.util.getNodeCrypto()),
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path: '../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
beforeEach: function() {
|
||||
openpgp.config.use_native = true;
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO find test vectors
|
||||
|
||||
@@ -98,22 +98,5 @@ describe('Elliptic Curve Cryptography for NIST P-256,P-384,P-521 curves @lightwe
|
||||
expect(result.signatures[0].valid).to.be.true;
|
||||
});
|
||||
|
||||
tryTests('ECC Worker Tests', omnibus, {
|
||||
if: typeof window !== 'undefined' && window.Worker,
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
beforeEach: function() {
|
||||
openpgp.config.use_native = true;
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO find test vectors
|
||||
});
|
||||
|
||||
@@ -2011,11 +2011,6 @@ function versionSpecificTests() {
|
||||
openpgp.config.prefer_hash_algorithm = openpgp.enums.hash.sha224;
|
||||
openpgp.config.compression = openpgp.enums.compression.zlib;
|
||||
openpgp.config.aead_mode = openpgp.enums.aead.experimental_gcm;
|
||||
if (openpgp.getWorker()) {
|
||||
openpgp.getWorker().workers.forEach(worker => {
|
||||
openpgp.getWorker().callWorker(worker, 'configure', openpgp.config);
|
||||
});
|
||||
}
|
||||
|
||||
const testPref = function(key) {
|
||||
// key flags
|
||||
@@ -2055,11 +2050,6 @@ function versionSpecificTests() {
|
||||
openpgp.config.prefer_hash_algorithm = prefer_hash_algorithmVal;
|
||||
openpgp.config.compression = compressionVal;
|
||||
openpgp.config.aead_mode = aead_modeVal;
|
||||
if (openpgp.getWorker()) {
|
||||
openpgp.getWorker().workers.forEach(worker => {
|
||||
openpgp.getWorker().callWorker(worker, 'configure', openpgp.config);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2565,27 +2555,6 @@ describe('Key', function() {
|
||||
}
|
||||
});
|
||||
|
||||
tryTests('V4 - With Worker', versionSpecificTests, {
|
||||
if: typeof window !== 'undefined' && window.Worker,
|
||||
beforeEach: function() {
|
||||
v5_keysVal = openpgp.config.v5_keys;
|
||||
openpgp.config.v5_keys = false;
|
||||
},
|
||||
afterEach: function() {
|
||||
openpgp.config.v5_keys = v5_keysVal;
|
||||
},
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path: '../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
tryTests('V5', versionSpecificTests, {
|
||||
if: !openpgp.config.ci,
|
||||
beforeEach: function() {
|
||||
|
||||
@@ -404,11 +404,6 @@ function withCompression(tests) {
|
||||
return options;
|
||||
},
|
||||
function() {
|
||||
// Disable the call expectations when using the web worker because it's not possible to spy on what functions get called.
|
||||
if (openpgp.getWorker()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (compression === openpgp.enums.compression.uncompressed) {
|
||||
expect(compressSpy.called).to.be.false;
|
||||
expect(decompressSpy.called).to.be.false;
|
||||
@@ -439,28 +434,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
rsaGenStub.restore();
|
||||
});
|
||||
|
||||
describe('initWorker, getWorker, destroyWorker - unit tests', function() {
|
||||
afterEach(function() {
|
||||
openpgp.destroyWorker(); // cleanup worker in case of failure
|
||||
});
|
||||
|
||||
it('should work', async function() {
|
||||
const workerStub = {
|
||||
postMessage: function() {},
|
||||
terminate: function() {}
|
||||
};
|
||||
await Promise.all([
|
||||
openpgp.initWorker({
|
||||
workers: [workerStub]
|
||||
}),
|
||||
workerStub.onmessage({ data: { id: 0, event: 'method-return' } })
|
||||
]);
|
||||
expect(openpgp.getWorker()).to.exist;
|
||||
openpgp.destroyWorker();
|
||||
expect(openpgp.getWorker()).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateKey - validate user ids', function() {
|
||||
it('should fail for invalid user name', async function() {
|
||||
const opt = {
|
||||
@@ -571,7 +544,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
|
||||
afterEach(function() {
|
||||
keyGenStub.restore();
|
||||
openpgp.destroyWorker();
|
||||
getWebCryptoAllStub.restore();
|
||||
});
|
||||
|
||||
@@ -598,30 +570,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
expect(newKey.publicKeyArmored).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
it('should delegate to async proxy', async function() {
|
||||
const workerStub = {
|
||||
postMessage: function() {},
|
||||
terminate: function() {}
|
||||
};
|
||||
await Promise.all([
|
||||
openpgp.initWorker({
|
||||
workers: [workerStub]
|
||||
}),
|
||||
workerStub.onmessage({ data: { id: 0, event: 'method-return' } })
|
||||
]);
|
||||
const proxyGenStub = stub(openpgp.getWorker(), 'delegate');
|
||||
getWebCryptoAllStub.returns();
|
||||
|
||||
const opt = {
|
||||
userIds: { name: 'Test User', email: 'text@example.com' },
|
||||
passphrase: 'secret',
|
||||
subkeys: []
|
||||
};
|
||||
openpgp.generateKey(opt);
|
||||
expect(proxyGenStub.calledOnce).to.be.true;
|
||||
expect(keyGenStub.calledOnce).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateKey - integration tests', function() {
|
||||
@@ -633,30 +581,10 @@ describe('OpenPGP.js public api tests', function() {
|
||||
|
||||
afterEach(function() {
|
||||
openpgp.config.use_native = use_nativeVal;
|
||||
openpgp.destroyWorker();
|
||||
});
|
||||
|
||||
it('should work in JS (without worker)', function() {
|
||||
it('should work in JS', function() {
|
||||
openpgp.config.use_native = false;
|
||||
openpgp.destroyWorker();
|
||||
const opt = {
|
||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||
};
|
||||
|
||||
return openpgp.generateKey(opt).then(function(newKey) {
|
||||
expect(newKey.key.getUserIds()[0]).to.equal('Test User <text@example.com>');
|
||||
expect(newKey.publicKeyArmored).to.match(/^-----BEGIN PGP PUBLIC/);
|
||||
expect(newKey.privateKeyArmored).to.match(/^-----BEGIN PGP PRIVATE/);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work in JS (with worker)', async function() {
|
||||
openpgp.config.use_native = false;
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
const opt = {
|
||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||
};
|
||||
@@ -692,7 +620,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
let privateKey;
|
||||
let publicKey;
|
||||
let publicKeyNoAEAD;
|
||||
let zero_copyVal;
|
||||
let use_nativeVal;
|
||||
let aead_protectVal;
|
||||
let aead_modeVal;
|
||||
@@ -709,7 +636,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
publicKey_2038_2045 = privateKey_2038_2045.toPublic();
|
||||
privateKey_1337 = await openpgp.key.readArmored(priv_key_expires_1337);
|
||||
publicKey_1337 = privateKey_1337.toPublic();
|
||||
zero_copyVal = openpgp.config.zero_copy;
|
||||
use_nativeVal = openpgp.config.use_native;
|
||||
aead_protectVal = openpgp.config.aead_protect;
|
||||
aead_modeVal = openpgp.config.aead_mode;
|
||||
@@ -718,7 +644,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
openpgp.config.zero_copy = zero_copyVal;
|
||||
openpgp.config.use_native = use_nativeVal;
|
||||
openpgp.config.aead_protect = aead_protectVal;
|
||||
openpgp.config.aead_mode = aead_modeVal;
|
||||
@@ -729,9 +654,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
it('Configuration', async function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (openpgp.getWorker()) { // init again to trigger config event
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
}
|
||||
|
||||
return openpgp.encrypt({ publicKeys:publicKey, message:openpgp.message.fromText(plaintext) }).then(function(encrypted) {
|
||||
expect(encrypted).to.exist;
|
||||
expect(encrypted).not.to.match(/^Version:/);
|
||||
@@ -739,48 +662,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Test multiple workers', async function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (!openpgp.getWorker()) {
|
||||
return;
|
||||
}
|
||||
const { workers } = openpgp.getWorker();
|
||||
try {
|
||||
await privateKey.decrypt(passphrase)
|
||||
try {
|
||||
await openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 2});
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
|
||||
const workerTest = (_, index) => {
|
||||
const plaintext = input.createSomeMessage() + index;
|
||||
return openpgp.encrypt({
|
||||
publicKeys: publicKey,
|
||||
data: plaintext
|
||||
}).then(function (encrypted) {
|
||||
expect(encrypted).to.exist;
|
||||
expect(encrypted).not.to.match(/^Version:/);
|
||||
expect(encrypted).to.match(/Comment: different/);
|
||||
return openpgp.decrypt({
|
||||
privateKeys: privateKey,
|
||||
message: openpgp.message.readArmored(encrypted)
|
||||
});
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
});
|
||||
};
|
||||
await Promise.all(Array(10).fill(null).map(workerTest));
|
||||
} finally {
|
||||
try {
|
||||
await openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 1 });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('Decrypting key with wrong passphrase rejected', async function () {
|
||||
await expect(privateKey.decrypt('wrong passphrase')).to.eventually.be.rejectedWith('Incorrect key passphrase');
|
||||
});
|
||||
@@ -827,29 +708,12 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
|
||||
tryTests('CFB mode (asm.js)', tests, {
|
||||
if: !(typeof window !== 'undefined' && window.Worker),
|
||||
if: true,
|
||||
beforeEach: function() {
|
||||
openpgp.config.aead_protect = false;
|
||||
}
|
||||
});
|
||||
|
||||
tryTests('CFB mode (asm.js, worker)', tests, {
|
||||
if: typeof window !== 'undefined' && window.Worker,
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
beforeEach: function() {
|
||||
openpgp.config.aead_protect = false;
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
tryTests('GCM mode (V5 keys)', tests, {
|
||||
if: true,
|
||||
beforeEach: function() {
|
||||
@@ -1576,11 +1440,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||
const badBodyEncrypted = data.replace(/\n=([a-zA-Z0-9/+]{4})/, 'aaa\n=$1');
|
||||
for (let allow_streaming = 1; allow_streaming >= 0; allow_streaming--) {
|
||||
openpgp.config.allow_unauthenticated_stream = !!allow_streaming;
|
||||
if (openpgp.getWorker()) {
|
||||
openpgp.getWorker().workers.forEach(worker => {
|
||||
openpgp.getWorker().callWorker(worker, 'configure', openpgp.config);
|
||||
});
|
||||
}
|
||||
await Promise.all([badSumEncrypted, badBodyEncrypted].map(async (encrypted, i) => {
|
||||
await Promise.all([
|
||||
encrypted,
|
||||
@@ -1777,8 +1636,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with binary data and transferable objects', function () {
|
||||
openpgp.config.zero_copy = true; // activate transferable objects
|
||||
it('should encrypt and decrypt with binary data', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])),
|
||||
passwords: password1,
|
||||
@@ -1790,21 +1648,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await openpgp.message.read(encrypted);
|
||||
openpgp.config.zero_copy = false;
|
||||
if (openpgp.getWorker()) {
|
||||
openpgp.getWorker().workers.forEach(worker => {
|
||||
openpgp.getWorker().callWorker(worker, 'configure', openpgp.config);
|
||||
});
|
||||
}
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
if (openpgp.getWorker()) {
|
||||
if (navigator.userAgent.indexOf('Safari') !== -1 && (navigator.userAgent.indexOf('Version/11.1') !== -1 || (navigator.userAgent.match(/Chrome\/(\d+)/) || [])[1] < 56)) {
|
||||
expect(encOpt.message.packets[0].data.byteLength).to.equal(8); // browser doesn't support transfering buffers
|
||||
} else {
|
||||
expect(encOpt.message.packets[0].data.byteLength).to.equal(0); // transferred buffer should be empty
|
||||
}
|
||||
}
|
||||
expect(decrypted.data).to.deep.equal(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]));
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
|
||||
@@ -1331,20 +1331,6 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
||||
|
||||
tests();
|
||||
|
||||
tryTests('With Worker', tests, {
|
||||
if: typeof window !== 'undefined' && window.Worker,
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
let reject_message_hash_algorithms;
|
||||
tryTests('Accept SHA-1 signatures', tests, {
|
||||
if: true,
|
||||
|
||||
@@ -132,38 +132,6 @@ describe('Util unit tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTransferables', function() {
|
||||
const buf1 = new Uint8Array(1);
|
||||
const buf2 = new Uint8Array(1);
|
||||
const obj = {
|
||||
data1: buf1,
|
||||
data2: buf1,
|
||||
data3: {
|
||||
data4: buf2
|
||||
}
|
||||
};
|
||||
|
||||
it('should return undefined when zero_copy is false', function() {
|
||||
openpgp.config.zero_copy = false;
|
||||
expect(openpgp.util.getTransferables(obj, false)).to.be.undefined;
|
||||
});
|
||||
it('should return undefined for no input', function() {
|
||||
expect(openpgp.util.getTransferables(undefined, true)).to.be.undefined;
|
||||
});
|
||||
it('should return undefined for an empty oject', function() {
|
||||
expect(openpgp.util.getTransferables({}, true)).to.be.undefined;
|
||||
});
|
||||
if (typeof navigator !== 'undefined') {
|
||||
it('should return two buffers', function() {
|
||||
expect(openpgp.util.getTransferables(obj, true)).to.deep.equal(
|
||||
navigator.userAgent.indexOf('Safari') !== -1 && (navigator.userAgent.indexOf('Version/11.1') !== -1 || (navigator.userAgent.match(/Chrome\/(\d+)/) || [])[1] < 56) ?
|
||||
undefined :
|
||||
[buf1.buffer, buf2.buffer]
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Misc.", function() {
|
||||
it('util.readNumber should not overflow until full range of uint32', function () {
|
||||
const ints = [Math.pow(2, 20), Math.pow(2, 25), Math.pow(2, 30), Math.pow(2, 32) - 1];
|
||||
|
||||
@@ -220,7 +220,7 @@ const input = require('./testInputs');
|
||||
expect(publicKey).to.deep.equal(openpgp.util.hex_to_Uint8Array(vector.PUBLIC_KEY));
|
||||
const data = util.str_to_Uint8Array(vector.MESSAGE);
|
||||
const keyIntegers = [
|
||||
openpgp.OID.fromClone(curve),
|
||||
new openpgp.OID(curve.oid),
|
||||
new openpgp.MPI(util.hex_to_str('40'+vector.PUBLIC_KEY)),
|
||||
new openpgp.MPI(util.hex_to_str(vector.SECRET_KEY))
|
||||
];
|
||||
@@ -538,19 +538,3 @@ tryTests('X25519 Omnibus Tests', omnibus, {
|
||||
if: !openpgp.config.ci
|
||||
});
|
||||
|
||||
tryTests('X25519 Omnibus Tests - Worker', omnibus, {
|
||||
if: typeof window !== 'undefined' && window.Worker,
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
},
|
||||
beforeEach: function() {
|
||||
openpgp.config.use_native = true;
|
||||
},
|
||||
after: function() {
|
||||
openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/* globals tryTests: true */
|
||||
|
||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
||||
|
||||
const chai = require('chai');
|
||||
|
||||
const { expect } = chai;
|
||||
|
||||
const pub_key =
|
||||
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||
'',
|
||||
'mI0EUmEvTgEEANyWtQQMOybQ9JltDqmaX0WnNPJeLILIM36sw6zL0nfTQ5zXSS3+',
|
||||
'fIF6P29lJFxpblWk02PSID5zX/DYU9/zjM2xPO8Oa4xo0cVTOTLj++Ri5mtr//f5',
|
||||
'GLsIXxFrBJhD/ghFsL3Op0GXOeLJ9A5bsOn8th7x6JucNKuaRB6bQbSPABEBAAG0',
|
||||
'JFRlc3QgTWNUZXN0aW5ndG9uIDx0ZXN0QGV4YW1wbGUuY29tPoi5BBMBAgAjBQJS',
|
||||
'YS9OAhsvBwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQSmNhOk1uQJQwDAP6',
|
||||
'AgrTyqkRlJVqz2pb46TfbDM2TDF7o9CBnBzIGoxBhlRwpqALz7z2kxBDmwpQa+ki',
|
||||
'Bq3jZN/UosY9y8bhwMAlnrDY9jP1gdCo+H0sD48CdXybblNwaYpwqC8VSpDdTndf',
|
||||
'9j2wE/weihGp/DAdy/2kyBCaiOY1sjhUfJ1GogF49rC4jQRSYS9OAQQA6R/PtBFa',
|
||||
'JaT4jq10yqASk4sqwVMsc6HcifM5lSdxzExFP74naUMMyEsKHP53QxTF0Grqusag',
|
||||
'Qg/ZtgT0CN1HUM152y7ACOdp1giKjpMzOTQClqCoclyvWOFB+L/SwGEIJf7LSCEr',
|
||||
'woBuJifJc8xAVr0XX0JthoW+uP91eTQ3XpsAEQEAAYkBPQQYAQIACQUCUmEvTgIb',
|
||||
'LgCoCRBKY2E6TW5AlJ0gBBkBAgAGBQJSYS9OAAoJEOCE90RsICyXuqIEANmmiRCA',
|
||||
'SF7YK7PvFkieJNwzeK0V3F2lGX+uu6Y3Q/Zxdtwc4xR+me/CSBmsURyXTO29OWhP',
|
||||
'GLszPH9zSJU9BdDi6v0yNprmFPX/1Ng0Abn/sCkwetvjxC1YIvTLFwtUL/7v6NS2',
|
||||
'bZpsUxRTg9+cSrMWWSNjiY9qUKajm1tuzPDZXAUEAMNmAN3xXN/Kjyvj2OK2ck0X',
|
||||
'W748sl/tc3qiKPMJ+0AkMF7Pjhmh9nxqE9+QCEl7qinFqqBLjuzgUhBU4QlwX1GD',
|
||||
'AtNTq6ihLMD5v1d82ZC7tNatdlDMGWnIdvEMCv2GZcuIqDQ9rXWs49e7tq1NncLY',
|
||||
'hz3tYjKhoFTKEIq3y3Pp',
|
||||
'=h/aX',
|
||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
||||
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
let pubKey;
|
||||
|
||||
tryTests('Async Proxy', tests, {
|
||||
if: typeof window !== 'undefined' && window.Worker && window.MessageChannel,
|
||||
before: async function() {
|
||||
try {
|
||||
await openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
}
|
||||
pubKey = await openpgp.key.readArmored(pub_key);
|
||||
},
|
||||
after: async function() {
|
||||
await openpgp.destroyWorker();
|
||||
}
|
||||
});
|
||||
|
||||
function tests() {
|
||||
|
||||
describe('Random number pipeline', function() {
|
||||
it('Random number buffer automatically reseeded', async function() {
|
||||
const worker = new Worker('../dist/openpgp.worker.js');
|
||||
const wProxy = new openpgp.AsyncProxy();
|
||||
try {
|
||||
await wProxy.init({ path:'../dist/openpgp.worker.js', workers: [worker] });
|
||||
} catch (e) {
|
||||
openpgp.util.print_debug_error(e);
|
||||
return;
|
||||
}
|
||||
return wProxy.delegate('encrypt', { publicKeys:[pubKey], message:openpgp.message.fromText(plaintext) });
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
describe('Web Worker', function () {
|
||||
require('./async_proxy.js');
|
||||
require('./application_worker.js');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user