1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-16 16:44:50 +02:00

Improve BCUtilTest

This commit is contained in:
Paul Schaub 2020-01-12 23:34:47 +01:00
parent 745e296799
commit fd13a1278a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -16,13 +16,12 @@
package org.pgpainless.util; package org.pgpainless.util;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException; import java.security.NoSuchProviderException;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -48,7 +47,7 @@ public class BCUtilTest {
@Test @Test
public void keyRingToCollectionTest() public void keyRingToCollectionTest()
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
IOException { IOException {
PGPKeyRing ring = PGPainless.generateKeyRing() PGPKeyRing ring = PGPainless.generateKeyRing()
.withSubKey(KeySpec.getBuilder(RSA_GENERAL.withLength(RsaLength._3072)).withDefaultKeyFlags().withDefaultAlgorithms()) .withSubKey(KeySpec.getBuilder(RSA_GENERAL.withLength(RsaLength._3072)).withDefaultKeyFlags().withDefaultAlgorithms())
@ -105,7 +104,7 @@ public class BCUtilTest {
@Test @Test
public void removeUnsignedKeysTest() public void removeUnsignedKeysTest()
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
PGPKeyRing alice = PGPainless.generateKeyRing().simpleRsaKeyRing("alice@wonderland.lit", RsaLength._1024); PGPKeyRing alice = PGPainless.generateKeyRing().simpleRsaKeyRing("alice@wonderland.lit", RsaLength._1024);
PGPKeyRing mallory = PGPainless.generateKeyRing().simpleEcKeyRing("mallory@mall.ory"); PGPKeyRing mallory = PGPainless.generateKeyRing().simpleEcKeyRing("mallory@mall.ory");
@ -140,11 +139,11 @@ public class BCUtilTest {
PGPSecretKeyRing secretKeys = ring.getSecretKeys(); PGPSecretKeyRing secretKeys = ring.getSecretKeys();
PGPSecretKeyRing secCleaned = ring.getSecretKeys(); PGPSecretKeyRing secCleaned = ring.getSecretKeys();
assertTrue(Arrays.equals(secretKeys.getEncoded(), secCleaned.getEncoded())); assertArrayEquals(secretKeys.getEncoded(), secCleaned.getEncoded());
PGPPublicKeyRing pubCleaned = BCUtil.removeUnassociatedKeysFromKeyRing(publicKeys, publicKeys.getPublicKey()); PGPPublicKeyRing pubCleaned = BCUtil.removeUnassociatedKeysFromKeyRing(publicKeys, publicKeys.getPublicKey());
assertTrue(Arrays.equals(publicKeys.getEncoded(), pubCleaned.getEncoded())); assertArrayEquals(publicKeys.getEncoded(), pubCleaned.getEncoded());
} }
} }