1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-01-09 19:57:57 +01:00

Test if userId is present

This commit is contained in:
Paul Schaub 2020-10-16 13:18:07 +02:00
parent 11e7bc69fc
commit 2f85c9a8d0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -1,17 +1,19 @@
package org.pgpainless.key.generation; package org.pgpainless.key.generation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.junit.Test; import org.junit.Test;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.key.collection.PGPKeyRing; import org.pgpainless.key.collection.PGPKeyRing;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.RSA_SIGN; import org.pgpainless.key.generation.type.RSA_SIGN;
import org.pgpainless.key.generation.type.length.RsaLength; import org.pgpainless.key.generation.type.length.RsaLength;
@ -28,11 +30,17 @@ public class GenerateKeyWithAdditionalUserIdTest {
.withoutPassphrase() .withoutPassphrase()
.build(); .build();
Iterator<String> userIds = keyRing.getPublicKeys().getPublicKey().getUserIDs();
assertEquals("primary@user.id", userIds.next());
assertEquals("additional@user.id", userIds.next());
assertFalse(userIds.hasNext());
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(byteOut); ArmoredOutputStream armor = new ArmoredOutputStream(byteOut);
keyRing.getSecretKeys().encode(armor); keyRing.getSecretKeys().encode(armor);
armor.close(); armor.close();
// echo this | gpg --list-packets
System.out.println(byteOut.toString("UTF-8")); System.out.println(byteOut.toString("UTF-8"));
} }
} }