mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-18 02:12:06 +01:00
Add deprecated utility methods for deleting user-ids from keys/certificates
This commit is contained in:
parent
e4d1aa7edf
commit
0f77d81bd1
1 changed files with 46 additions and 0 deletions
|
@ -154,4 +154,50 @@ public final class KeyRingUtils {
|
|||
long keyId) {
|
||||
return ring.getPublicKey(keyId) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given user-id and its certification signatures from the given key.
|
||||
*
|
||||
* @deprecated Deleting user-ids is highly discouraged, since it might lead to all sorts of problems
|
||||
* (e.g. lost key properties).
|
||||
* Instead, user-ids should only be revoked.
|
||||
*
|
||||
* @param secretKeys secret keys
|
||||
* @param userId user-id
|
||||
* @return modified secret keys
|
||||
*/
|
||||
@Deprecated
|
||||
public PGPSecretKeyRing deleteUserIdFromSecretKeyRing(PGPSecretKeyRing secretKeys, String userId) {
|
||||
PGPSecretKey secretKey = secretKeys.getSecretKey(); // user-ids are located on primary key only
|
||||
PGPPublicKey publicKey = secretKey.getPublicKey(); // user-ids are placed on the public key part
|
||||
publicKey = PGPPublicKey.removeCertification(publicKey, userId);
|
||||
if (publicKey == null) {
|
||||
throw new NoSuchElementException("User-ID " + userId + " not found on the key.");
|
||||
}
|
||||
secretKey = PGPSecretKey.replacePublicKey(secretKey, publicKey);
|
||||
secretKeys = PGPSecretKeyRing.insertSecretKey(secretKeys, secretKey);
|
||||
return secretKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given user-id and its certification signatures from the given certificate.
|
||||
*
|
||||
* @deprecated Deleting user-ids is highly discouraged, since it might lead to all sorts of problems
|
||||
* (e.g. lost key properties).
|
||||
* Instead, user-ids should only be revoked.
|
||||
*
|
||||
* @param publicKeys certificate
|
||||
* @param userId user-id
|
||||
* @return modified secret keys
|
||||
*/
|
||||
@Deprecated
|
||||
public PGPPublicKeyRing deleteUserIdFromPublicKeyRing(PGPPublicKeyRing publicKeys, String userId) {
|
||||
PGPPublicKey publicKey = publicKeys.getPublicKey(); // user-ids are located on primary key only
|
||||
publicKey = PGPPublicKey.removeCertification(publicKey, userId);
|
||||
if (publicKey == null) {
|
||||
throw new NoSuchElementException("User-ID " + userId + " not found on the key.");
|
||||
}
|
||||
publicKeys = PGPPublicKeyRing.insertPublicKey(publicKeys, publicKey);
|
||||
return publicKeys;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue