1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-27 21:37:58 +01:00

Add support for deleting subKeys (untested)

This commit is contained in:
Paul Schaub 2020-11-03 19:32:01 +01:00
parent 2d899e0a3b
commit 92e2828885
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -157,12 +157,23 @@ public class KeyRingEditor implements KeyRingEditorInterface {
@Override
public KeyRingEditorInterface deleteSubKey(OpenPgpV4Fingerprint fingerprint, SecretKeyRingProtector protector) {
throw new NotYetImplementedException();
return deleteSubKey(fingerprint.getKeyId(), protector);
}
@Override
public KeyRingEditorInterface deleteSubKey(long subKeyId, SecretKeyRingProtector protector) {
throw new NotYetImplementedException();
if (secretKeyRing.getSecretKey().getKeyID() == subKeyId) {
throw new IllegalArgumentException("You cannot delete the primary key of this key ring.");
}
PGPSecretKey deleteMe = secretKeyRing.getSecretKey(subKeyId);
if (deleteMe == null) {
throw new NoSuchElementException("KeyRing does not contain such a key.");
}
PGPSecretKeyRing newKeyRing = PGPSecretKeyRing.removeSecretKey(secretKeyRing, deleteMe);
secretKeyRing = newKeyRing;
return this;
}
@Override