1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-17 09:41:08 +01:00

Add tests for SubkeyIdentifier

This commit is contained in:
Paul Schaub 2021-08-01 17:19:04 +02:00
parent 99ff6d537b
commit 1327e08ac3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 127 additions and 5 deletions

View file

@ -18,7 +18,6 @@ package org.pgpainless.key;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
/**
* Tuple class used to identify a subkey by fingerprints of the primary key of the subkeys key ring,
@ -29,6 +28,16 @@ public class SubkeyIdentifier {
private final OpenPgpV4Fingerprint primaryKeyFingerprint;
private final OpenPgpV4Fingerprint subkeyFingerprint;
/**
* Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing}.
* The identifier will point to the primary key of the provided ring.
*
* @param keyRing key ring
*/
public SubkeyIdentifier(PGPKeyRing keyRing) {
this(keyRing, keyRing.getPublicKey().getKeyID());
}
/**
* Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing} and the subkeys key id.
* {@link #getPrimaryKeyFingerprint()} will return the {@link OpenPgpV4Fingerprint} of the keyrings primary key,
@ -41,6 +50,10 @@ public class SubkeyIdentifier {
this(new OpenPgpV4Fingerprint(keyRing.getPublicKey()), new OpenPgpV4Fingerprint(keyRing.getPublicKey(keyId)));
}
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpV4Fingerprint subkeyFingerprint) {
this(new OpenPgpV4Fingerprint(keyRing), subkeyFingerprint);
}
/**
* Create a {@link SubkeyIdentifier} that identifies the primary key with the given fingerprint.
* This means, both {@link #getPrimaryKeyFingerprint()} and {@link #getSubkeyFingerprint()} return the same.
@ -63,10 +76,6 @@ public class SubkeyIdentifier {
this.subkeyFingerprint = subkeyFingerprint;
}
public SubkeyIdentifier(PGPSecretKeyRing secretKeys) {
this(secretKeys, secretKeys.getPublicKey().getKeyID());
}
public @Nonnull OpenPgpV4Fingerprint getFingerprint() {
return getSubkeyFingerprint();
}