mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-16 17:32:06 +01:00
Add methods to access delegations and 3rd-party certifications from keys
This commit is contained in:
parent
cb594c3b2c
commit
42c1765941
1 changed files with 50 additions and 0 deletions
|
@ -23,6 +23,7 @@ import org.bouncycastle.openpgp.PGPCompressedData;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||||
import org.bouncycastle.util.encoders.Hex;
|
import org.bouncycastle.util.encoders.Hex;
|
||||||
|
@ -307,4 +308,53 @@ public final class SignatureUtils {
|
||||||
|
|
||||||
return Collections.unmodifiableList(signaturesByKeyId);
|
return Collections.unmodifiableList(signaturesByKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nonnull List<PGPSignature> getDelegations(PGPPublicKeyRing key) {
|
||||||
|
List<PGPSignature> delegations = new ArrayList<>();
|
||||||
|
PGPPublicKey primaryKey = key.getPublicKey();
|
||||||
|
Iterator<PGPSignature> signatures = primaryKey.getKeySignatures();
|
||||||
|
outerloop: while (signatures.hasNext()) {
|
||||||
|
PGPSignature signature = signatures.next();
|
||||||
|
Iterator<PGPPublicKey> subkeys = key.getPublicKeys();
|
||||||
|
while (subkeys.hasNext()) {
|
||||||
|
if (signature.getKeyID() == subkeys.next().getKeyID()) {
|
||||||
|
continue outerloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delegations.add(signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
return delegations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nonnull List<PGPSignature> get3rdPartyCertificationsFor(String userId, PGPPublicKeyRing key) {
|
||||||
|
PGPPublicKey primaryKey = key.getPublicKey();
|
||||||
|
List<PGPSignature> certifications = new ArrayList<>();
|
||||||
|
Iterator<PGPSignature> it = primaryKey.getSignaturesForID(userId);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
PGPSignature sig = it.next();
|
||||||
|
if (sig.getKeyID() != primaryKey.getKeyID()) {
|
||||||
|
certifications.add(sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return certifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Certification {
|
||||||
|
private final String userId;
|
||||||
|
private final PGPSignature signature;
|
||||||
|
|
||||||
|
public Certification(String userId, PGPSignature signature) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.signature = signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PGPSignature getSignature() {
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue