Add tests

This commit is contained in:
Daniel Huigens 2024-07-15 14:32:11 +02:00
parent a4b2b1449e
commit 5a4c73dd7d

View File

@ -4129,6 +4129,34 @@ CNa5yq6lyexhsn2Vs8DsX+SOSUyNJiy5FyIJ
expect(aeadAlgo).to.equal(openpgp.enums.aead.gcm); expect(aeadAlgo).to.equal(openpgp.enums.aead.gcm);
}); });
it('getPreferredCipherSuite with AEAD - one key - AES256-OCB', async function() {
const [key1] = await openpgp.readKeys({ armoredKeys: twoKeys });
const primaryUser = await key1.getPrimaryUser();
primaryUser.selfCertification.features = [9]; // Monkey-patch SEIPDv2 feature flag
primaryUser.selfCertification.preferredCipherSuites = [[9, 2]];
const { symmetricAlgo, aeadAlgo } = await getPreferredCipherSuite([key1], undefined, undefined, {
...openpgp.config,
aeadProtect: true,
preferredAEADAlgorithm: openpgp.enums.aead.gcm
});
expect(symmetricAlgo).to.equal(openpgp.enums.symmetric.aes256);
expect(aeadAlgo).to.equal(openpgp.enums.aead.ocb);
});
it('getPreferredCipherSuite with AEAD - one key - AES128-GCM', async function() {
const [key1] = await openpgp.readKeys({ armoredKeys: twoKeys });
const primaryUser = await key1.getPrimaryUser();
primaryUser.selfCertification.features = [9]; // Monkey-patch SEIPDv2 feature flag
primaryUser.selfCertification.preferredCipherSuites = [[7, 3]];
const { symmetricAlgo, aeadAlgo } = await getPreferredCipherSuite([key1], undefined, undefined, {
...openpgp.config,
aeadProtect: true,
preferredAEADAlgorithm: openpgp.enums.aead.gcm
});
expect(symmetricAlgo).to.equal(openpgp.enums.symmetric.aes128);
expect(aeadAlgo).to.equal(openpgp.enums.aead.gcm);
});
it('getPreferredCipherSuite with AEAD - two keys - one without pref', async function() { it('getPreferredCipherSuite with AEAD - two keys - one without pref', async function() {
const keys = await openpgp.readKeys({ armoredKeys: twoKeys }); const keys = await openpgp.readKeys({ armoredKeys: twoKeys });
const key1 = keys[0]; const key1 = keys[0];