1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-10 02:39:39 +02:00

Port ReadKeys example

This commit is contained in:
Paul Schaub 2025-04-07 16:30:27 +02:00
parent dad4e28580
commit ec86391d03
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -24,6 +24,7 @@ public class ReadKeys {
*/ */
@Test @Test
public void readCertificate() throws IOException { public void readCertificate() throws IOException {
PGPainless api = PGPainless.getInstance();
String certificate = "" + String certificate = "" +
"-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"Comment: Alice's OpenPGP certificate\n" + "Comment: Alice's OpenPGP certificate\n" +
@ -40,9 +41,9 @@ public class ReadKeys {
"=iIGO\n" + "=iIGO\n" +
"-----END PGP PUBLIC KEY BLOCK-----"; "-----END PGP PUBLIC KEY BLOCK-----";
OpenPGPCertificate publicKey = PGPainless.getInstance().readKey().parseCertificate(certificate); OpenPGPCertificate publicKey = api.readKey().parseCertificate(certificate);
KeyRingInfo keyInfo = PGPainless.inspectKeyRing(publicKey); KeyRingInfo keyInfo = api.inspect(publicKey);
OpenPgpFingerprint fingerprint = new OpenPgpV4Fingerprint("EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E"); OpenPgpFingerprint fingerprint = new OpenPgpV4Fingerprint("EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E");
assertEquals(fingerprint, keyInfo.getFingerprint()); assertEquals(fingerprint, keyInfo.getFingerprint());
assertEquals("Alice Lovelace <alice@openpgp.example>", keyInfo.getPrimaryUserId()); assertEquals("Alice Lovelace <alice@openpgp.example>", keyInfo.getPrimaryUserId());
@ -53,6 +54,7 @@ public class ReadKeys {
*/ */
@Test @Test
public void readSecretKey() throws IOException { public void readSecretKey() throws IOException {
PGPainless api = PGPainless.getInstance();
String key = "\n" + String key = "\n" +
"-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"Comment: Alice's OpenPGP Transferable Secret Key\n" + "Comment: Alice's OpenPGP Transferable Secret Key\n" +
@ -71,9 +73,9 @@ public class ReadKeys {
"=n8OM\n" + "=n8OM\n" +
"-----END PGP PRIVATE KEY BLOCK-----"; "-----END PGP PRIVATE KEY BLOCK-----";
OpenPGPKey secretKey = PGPainless.getInstance().readKey().parseKey(key); OpenPGPKey secretKey = api.readKey().parseKey(key);
KeyRingInfo keyInfo = PGPainless.inspectKeyRing(secretKey); KeyRingInfo keyInfo = api.inspect(secretKey);
OpenPgpFingerprint fingerprint = new OpenPgpV4Fingerprint("EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E"); OpenPgpFingerprint fingerprint = new OpenPgpV4Fingerprint("EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E");
assertEquals(fingerprint, keyInfo.getFingerprint()); assertEquals(fingerprint, keyInfo.getFingerprint());
assertEquals("Alice Lovelace <alice@openpgp.example>", keyInfo.getPrimaryUserId()); assertEquals("Alice Lovelace <alice@openpgp.example>", keyInfo.getPrimaryUserId());
@ -87,6 +89,7 @@ public class ReadKeys {
*/ */
@Test @Test
public void readKeyRingCollection() throws IOException { public void readKeyRingCollection() throws IOException {
PGPainless api = PGPainless.getInstance();
String certificateCollection = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String certificateCollection = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"Comment: Alice's OpenPGP certificate\n" + "Comment: Alice's OpenPGP certificate\n" +
"\n" + "\n" +
@ -145,7 +148,7 @@ public class ReadKeys {
"=NXei\n" + "=NXei\n" +
"-----END PGP PUBLIC KEY BLOCK-----"; "-----END PGP PUBLIC KEY BLOCK-----";
List<OpenPGPCertificate> collection = PGPainless.getInstance().readKey().parseKeysOrCertificates(certificateCollection); List<OpenPGPCertificate> collection = api.readKey().parseKeysOrCertificates(certificateCollection);
assertEquals(2, collection.size()); assertEquals(2, collection.size());
} }
} }