mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-17 17:51:08 +01:00
SubkeyIdentifier: Throw NoSuchElementException for non-existent subkey
This commit is contained in:
parent
1327e08ac3
commit
e4fdc3bc1e
2 changed files with 15 additions and 1 deletions
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package org.pgpainless.key;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
|
||||
/**
|
||||
* Tuple class used to identify a subkey by fingerprints of the primary key of the subkeys key ring,
|
||||
|
|
@ -47,7 +49,12 @@ public class SubkeyIdentifier {
|
|||
* @param keyId keyid of the subkey
|
||||
*/
|
||||
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, long keyId) {
|
||||
this(new OpenPgpV4Fingerprint(keyRing.getPublicKey()), new OpenPgpV4Fingerprint(keyRing.getPublicKey(keyId)));
|
||||
PGPPublicKey subkey = keyRing.getPublicKey(keyId);
|
||||
if (subkey == null) {
|
||||
throw new NoSuchElementException("Key ring does not contain subkey with id " + Long.toHexString(keyId));
|
||||
}
|
||||
this.primaryKeyFingerprint = new OpenPgpV4Fingerprint(keyRing);
|
||||
this.subkeyFingerprint = new OpenPgpV4Fingerprint(subkey);
|
||||
}
|
||||
|
||||
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpV4Fingerprint subkeyFingerprint) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue