1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-19 02:42:05 +01:00

Simplify some tests

This commit is contained in:
Paul Schaub 2018-06-21 15:35:40 +02:00
parent 0c99c52955
commit b08c34e9c9
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -64,8 +64,8 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
public void freshKeysRsaToRsaTest() public void freshKeysRsaToRsaTest()
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
IOException { IOException {
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("hatter@wonderland.lit", RsaLength._4096); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("alice@wonderland.lit", RsaLength._4096); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@ -73,8 +73,8 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
@Test @Test
public void freshKeysEcToEcTest() throws IOException, PGPException, NoSuchAlgorithmException, NoSuchProviderException, public void freshKeysEcToEcTest() throws IOException, PGPException, NoSuchAlgorithmException, NoSuchProviderException,
InvalidAlgorithmParameterException { InvalidAlgorithmParameterException {
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("hatter@wonderland.lit"); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@ -83,8 +83,8 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
public void freshKeysEcToRsaTest() public void freshKeysEcToRsaTest()
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
IOException { IOException {
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("hatter@wonderland.lit"); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("alice@wonderland.lit", RsaLength._4096); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@ -93,8 +93,8 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
public void freshKeysRsaToEcTest() public void freshKeysRsaToEcTest()
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
IOException { IOException {
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("hatter@wonderland.lit", RsaLength._4096); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@ -108,7 +108,7 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
SecretKeyRingProtector keyDecryptor = new UnprotectedKeysProtector(); SecretKeyRingProtector keyDecryptor = new UnprotectedKeysProtector();
byte[] secretMessage = (testMessage).getBytes(UTF8); byte[] secretMessage = testMessage.getBytes(UTF8);
ByteArrayOutputStream envelope = new ByteArrayOutputStream(); ByteArrayOutputStream envelope = new ByteArrayOutputStream();
@ -133,16 +133,17 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
DecryptionStream decryptor = PGPainless.createDecryptor() DecryptionStream decryptor = PGPainless.createDecryptor()
.onInputStream(envelopeIn) .onInputStream(envelopeIn)
.decryptWith(BCUtil.keyRingsToKeyRingCollection(recipient), keyDecryptor) .decryptWith(BCUtil.keyRingsToKeyRingCollection(recipient), keyDecryptor)
.verifyWith(Collections.singleton(senderPub.getPublicKey().getKeyID()), BCUtil.keyRingsToKeyRingCollection(senderPub)) .verifyWith(Collections.singleton(senderPub.getPublicKey().getKeyID()),
BCUtil.keyRingsToKeyRingCollection(senderPub))
.ignoreMissingPublicKeys() .ignoreMissingPublicKeys()
.build(); .build();
OutputStream decryptedSecretMessage = new ByteArrayOutputStream(); ByteArrayOutputStream decryptedSecretMessage = new ByteArrayOutputStream();
Streams.pipeAll(decryptor, decryptedSecretMessage); Streams.pipeAll(decryptor, decryptedSecretMessage);
decryptor.close(); decryptor.close();
assertTrue(Arrays.equals(secretMessage, ((ByteArrayOutputStream) decryptedSecretMessage).toByteArray())); assertTrue(Arrays.equals(secretMessage, decryptedSecretMessage.toByteArray()));
PainlessResult result = decryptor.getResult(); PainlessResult result = decryptor.getResult();
assertTrue(result.containsVerifiedSignatureFrom(senderPub)); assertTrue(result.containsVerifiedSignatureFrom(senderPub));
assertTrue(result.isIntegrityProtected()); assertTrue(result.isIntegrityProtected());