Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Mar 12, 2021
1 parent 24814d3 commit 6ee7610
Showing 1 changed file with 35 additions and 53 deletions.
88 changes: 35 additions & 53 deletions test/general/brainpool.js
Expand Up @@ -279,61 +279,43 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
});

function omnibus() {
it('Omnibus BrainpoolP256r1 Test', function() {
const options = { userIds: { name: "Hi", email: "hi@hel.lo" }, curve: "brainpoolP256r1" };
return openpgp.generateKey(options).then(function(firstKey) {
const hi = firstKey.key;
const pubHi = hi.toPublic();
it('Omnibus BrainpoolP256r1 Test', async function() {
const testData = input.createSomeMessage();
const testData2 = input.createSomeMessage();

const options = { userIds: { name: "Bye", email: "bye@good.bye" }, curve: "brainpoolP256r1" };
return openpgp.generateKey(options).then(function(secondKey) {
const bye = secondKey.key;
const pubBye = bye.toPublic();
const firstKey = await openpgp.generateKey({ userIds: { name: "Hi", email: "hi@hel.lo" }, curve: "brainpoolP256r1" });
const hi = firstKey.key;
const pubHi = hi.toPublic();
const secondKey = await openpgp.generateKey({ userIds: { name: "Bye", email: "bye@good.bye" }, curve: "brainpoolP256r1" });
const bye = secondKey.key;
const pubBye = bye.toPublic();

const testData = input.createSomeMessage();
const testData2 = input.createSomeMessage();
return Promise.all([
// Signing message
openpgp.sign(
{ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi }
).then(async signed => {
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed });
// Verifying signed message
return Promise.all([
openpgp.verify(
{ message: msg, publicKeys: pubHi }
).then(output => expect(output.signatures[0].valid).to.be.true),
// Verifying detached signature
openpgp.verify({
message: openpgp.CleartextMessage.fromText(testData),
publicKeys: pubHi,
signature: msg.signature
}).then(output => expect(output.signatures[0].valid).to.be.true)
]);
}),
// Encrypting and signing
openpgp.encrypt(
{
message: openpgp.Message.fromText(testData2),
publicKeys: [pubBye],
privateKeys: [hi]
}
).then(async encrypted => {
const msg = await openpgp.readMessage({ armoredMessage: encrypted });
// Decrypting and verifying
return openpgp.decrypt(
{
message: msg,
privateKeys: bye,
publicKeys: [pubHi]
}
).then(output => {
expect(output.data).to.equal(testData2);
expect(output.signatures[0].valid).to.be.true;
});
})
]);
});
const cleartextMessage = await openpgp.sign({ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi });
await openpgp.verify({
message: await openpgp.readCleartextMessage({ cleartextMessage }),
publicKeys: pubHi
}).then(output => expect(output.signatures[0].valid).to.be.true);
// Verifying detached signature
await openpgp.verify({
message: openpgp.Message.fromText(util.removeTrailingSpaces(testData)),
publicKeys: pubHi,
signature: (await openpgp.readCleartextMessage({ cleartextMessage })).signature
}).then(output => expect(output.signatures[0].valid).to.be.true);

// Encrypting and signing
const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(testData2),
publicKeys: [pubBye],
privateKeys: [hi]
});
// Decrypting and verifying
return openpgp.decrypt({
message: await openpgp.readMessage({ armoredMessage: encrypted }),
privateKeys: bye,
publicKeys: [pubHi]
}).then(output => {
expect(output.data).to.equal(testData2);
expect(output.signatures[0].valid).to.be.true;
});
});
}
Expand Down

0 comments on commit 6ee7610

Please sign in to comment.