mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-27 06:42:05 +01:00
use PGPainless.readKeyRing().secretKeyRing()
This commit is contained in:
parent
c9982ccfe6
commit
a807ddbb4e
1 changed files with 2 additions and 17 deletions
|
@ -91,8 +91,7 @@ public class AddUserIdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteExistingAndAddNewUserIdToExistingKeyRing()
|
public void deleteExistingAndAddNewUserIdToExistingKeyRing() throws PGPException, IOException {
|
||||||
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
|
|
||||||
final String ARMORED_PRIVATE_KEY =
|
final String ARMORED_PRIVATE_KEY =
|
||||||
"-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" +
|
"-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" +
|
||||||
"xVgEX6UIExYJKwYBBAHaRw8BAQdAMfHf64wPQ2LC9In5AKYU/KT1qWvI7e7a\r\n" +
|
"xVgEX6UIExYJKwYBBAHaRw8BAQdAMfHf64wPQ2LC9In5AKYU/KT1qWvI7e7a\r\n" +
|
||||||
|
@ -109,8 +108,7 @@ public class AddUserIdTest {
|
||||||
"=bk4o\r\n" +
|
"=bk4o\r\n" +
|
||||||
"-----END PGP PRIVATE KEY BLOCK-----\r\n";
|
"-----END PGP PRIVATE KEY BLOCK-----\r\n";
|
||||||
|
|
||||||
PGPSecretKeyRing secretKeys = readArmoredPrivateKey(ARMORED_PRIVATE_KEY.getBytes(StandardCharsets.UTF_8));
|
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(ARMORED_PRIVATE_KEY);
|
||||||
|
|
||||||
Iterator<String> userIds = secretKeys.getSecretKey().getPublicKey().getUserIDs();
|
Iterator<String> userIds = secretKeys.getSecretKey().getPublicKey().getUserIDs();
|
||||||
assertEquals("<user@example.com>", userIds.next());
|
assertEquals("<user@example.com>", userIds.next());
|
||||||
assertFalse(userIds.hasNext());
|
assertFalse(userIds.hasNext());
|
||||||
|
@ -125,17 +123,4 @@ public class AddUserIdTest {
|
||||||
assertEquals("cheshirecat@wonderland.lit", userIds.next());
|
assertEquals("cheshirecat@wonderland.lit", userIds.next());
|
||||||
assertFalse(userIds.hasNext());
|
assertFalse(userIds.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PGPSecretKeyRing readArmoredPrivateKey(byte[] data) throws IOException, PGPException {
|
|
||||||
try (ByteArrayInputStream byteIn = new ByteArrayInputStream(data)) {
|
|
||||||
try (ArmoredInputStream armoredIn = new ArmoredInputStream(byteIn)) {
|
|
||||||
JcaPGPSecretKeyRingCollection keyRingCollection = new JcaPGPSecretKeyRingCollection(armoredIn);
|
|
||||||
Iterator<PGPSecretKeyRing> it = keyRingCollection.getKeyRings();
|
|
||||||
if (it.hasNext()) {
|
|
||||||
return it.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue