1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Rename UserIdSelectionStrategy -> SelectUserId

This commit is contained in:
Paul Schaub 2021-02-03 16:38:28 +01:00
parent 138ea0d572
commit 567291ac17
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 24 additions and 24 deletions

View file

@ -66,7 +66,7 @@ import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.key.util.SignatureUtils; import org.pgpainless.key.util.SignatureUtils;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.SignatureSubpacketGeneratorUtil; import org.pgpainless.util.SignatureSubpacketGeneratorUtil;
import org.pgpainless.util.selection.userid.UserIdSelectionStrategy; import org.pgpainless.util.selection.userid.SelectUserId;
public class SecretKeyRingEditor implements SecretKeyRingEditorInterface { public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
@ -148,13 +148,13 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
@Override @Override
public SecretKeyRingEditorInterface deleteUserIds(UserIdSelectionStrategy selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) { public SecretKeyRingEditorInterface deleteUserIds(SelectUserId selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) {
PGPPublicKey publicKey = secretKeyRing.getPublicKey(); PGPPublicKey publicKey = secretKeyRing.getPublicKey();
return deleteUserIds(publicKey.getKeyID(), selectionStrategy, secretKeyRingProtector); return deleteUserIds(publicKey.getKeyID(), selectionStrategy, secretKeyRingProtector);
} }
@Override @Override
public SecretKeyRingEditorInterface deleteUserIds(long keyId, UserIdSelectionStrategy selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) { public SecretKeyRingEditorInterface deleteUserIds(long keyId, SelectUserId selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) {
List<PGPPublicKey> publicKeys = new ArrayList<>(); List<PGPPublicKey> publicKeys = new ArrayList<>();
Iterator<PGPPublicKey> publicKeyIterator = secretKeyRing.getPublicKeys(); Iterator<PGPPublicKey> publicKeyIterator = secretKeyRing.getPublicKeys();
boolean foundKey = false; boolean foundKey = false;

View file

@ -32,7 +32,7 @@ import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.RevocationAttributes; import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.selection.userid.UserIdSelectionStrategy; import org.pgpainless.util.selection.userid.SelectUserId;
public interface SecretKeyRingEditorInterface { public interface SecretKeyRingEditorInterface {
@ -77,16 +77,16 @@ public interface SecretKeyRingEditorInterface {
} }
default SecretKeyRingEditorInterface deleteUserId(long keyId, String userId, SecretKeyRingProtector secretKeyRingProtector) { default SecretKeyRingEditorInterface deleteUserId(long keyId, String userId, SecretKeyRingProtector secretKeyRingProtector) {
return deleteUserIds(keyId, UserIdSelectionStrategy.exactMatch(userId), secretKeyRingProtector); return deleteUserIds(keyId, SelectUserId.exactMatch(userId), secretKeyRingProtector);
} }
SecretKeyRingEditorInterface deleteUserIds(UserIdSelectionStrategy selectionStrategy, SecretKeyRingProtector secretKeyRingProtector); SecretKeyRingEditorInterface deleteUserIds(SelectUserId selectionStrategy, SecretKeyRingProtector secretKeyRingProtector);
default SecretKeyRingEditorInterface deleteUserIds(OpenPgpV4Fingerprint fingerprint, UserIdSelectionStrategy selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) { default SecretKeyRingEditorInterface deleteUserIds(OpenPgpV4Fingerprint fingerprint, SelectUserId selectionStrategy, SecretKeyRingProtector secretKeyRingProtector) {
return deleteUserIds(fingerprint.getKeyId(), selectionStrategy, secretKeyRingProtector); return deleteUserIds(fingerprint.getKeyId(), selectionStrategy, secretKeyRingProtector);
} }
SecretKeyRingEditorInterface deleteUserIds(long keyId, UserIdSelectionStrategy selectionStrategy, SecretKeyRingProtector secretKeyRingProtector); SecretKeyRingEditorInterface deleteUserIds(long keyId, SelectUserId selectionStrategy, SecretKeyRingProtector secretKeyRingProtector);
/** /**
* Add a subkey to the key ring. * Add a subkey to the key ring.

View file

@ -21,7 +21,7 @@ import java.util.List;
import org.bouncycastle.openpgp.PGPKeyRing; import org.bouncycastle.openpgp.PGPKeyRing;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
public abstract class UserIdSelectionStrategy { public abstract class SelectUserId {
protected abstract boolean accept(String userId); protected abstract boolean accept(String userId);
@ -53,8 +53,8 @@ public abstract class UserIdSelectionStrategy {
return null; return null;
} }
public static UserIdSelectionStrategy containsSubstring(String query) { public static SelectUserId containsSubstring(String query) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
return userId.contains(query); return userId.contains(query);
@ -62,8 +62,8 @@ public abstract class UserIdSelectionStrategy {
}; };
} }
public static UserIdSelectionStrategy exactMatch(String query) { public static SelectUserId exactMatch(String query) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
return userId.equals(query); return userId.equals(query);
@ -71,8 +71,8 @@ public abstract class UserIdSelectionStrategy {
}; };
} }
public static UserIdSelectionStrategy startsWith(String substring) { public static SelectUserId startsWith(String substring) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
return userId.startsWith(substring); return userId.startsWith(substring);
@ -80,12 +80,12 @@ public abstract class UserIdSelectionStrategy {
}; };
} }
public static UserIdSelectionStrategy containsEmailAddress(String email) { public static SelectUserId containsEmailAddress(String email) {
return containsSubstring(email.matches("^<.+>$") ? email : '<' + email + '>'); return containsSubstring(email.matches("^<.+>$") ? email : '<' + email + '>');
} }
public static UserIdSelectionStrategy validUserId(PGPKeyRing keyRing) { public static SelectUserId validUserId(PGPKeyRing keyRing) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
return PGPainless.inspectKeyRing(keyRing).isUserIdValid(userId); return PGPainless.inspectKeyRing(keyRing).isUserIdValid(userId);
@ -93,12 +93,12 @@ public abstract class UserIdSelectionStrategy {
}; };
} }
public static UserIdSelectionStrategy and(UserIdSelectionStrategy... strategies) { public static SelectUserId and(SelectUserId... strategies) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
boolean accept = true; boolean accept = true;
for (UserIdSelectionStrategy strategy : strategies) { for (SelectUserId strategy : strategies) {
accept &= strategy.accept(userId); accept &= strategy.accept(userId);
} }
return accept; return accept;
@ -106,12 +106,12 @@ public abstract class UserIdSelectionStrategy {
}; };
} }
public static UserIdSelectionStrategy or(UserIdSelectionStrategy... strategies) { public static SelectUserId or(SelectUserId... strategies) {
return new UserIdSelectionStrategy() { return new SelectUserId() {
@Override @Override
protected boolean accept(String userId) { protected boolean accept(String userId) {
boolean accept = false; boolean accept = false;
for (UserIdSelectionStrategy strategy : strategies) { for (SelectUserId strategy : strategies) {
accept |= strategy.accept(userId); accept |= strategy.accept(userId);
} }
return accept; return accept;