diff options
author | Alex Fong <alexfongg@gmail.com> | 2016-05-15 23:22:08 +0800 |
---|---|---|
committer | Alex Fong <alexfongg@gmail.com> | 2016-05-15 23:26:09 +0800 |
commit | 614f46a630e5ce29926ad000edadf7e158c0d4b2 (patch) | |
tree | debcf009104ee1a8fc7dc0252f96f794e363003a /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp | |
parent | 664386afece0cfb4d6db214e786406b5ad632da7 (diff) | |
download | open-keychain-614f46a630e5ce29926ad000edadf7e158c0d4b2.tar.gz open-keychain-614f46a630e5ce29926ad000edadf7e158c0d4b2.tar.bz2 open-keychain-614f46a630e5ce29926ad000edadf7e158c0d4b2.zip |
Shifted duplicate method implementations from KeyRing to openpgp-api submodule
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java index 1ebab7847..3e1aa718d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java @@ -20,6 +20,8 @@ package org.sufficientlysecure.keychain.pgp; import android.text.TextUtils; +import org.openintents.openpgp.util.OpenPgpUtils; +import org.openintents.openpgp.util.OpenPgpUtils.UserId; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import java.io.Serializable; @@ -45,7 +47,7 @@ public abstract class KeyRing { abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException; - public UserId getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { + public OpenPgpUtils.UserId getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { return splitUserId(getPrimaryUserIdWithFallback()); } @@ -59,10 +61,6 @@ public abstract class KeyRing { abstract public int getVerified() throws PgpKeyNotFoundException; - private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); - - private static final Pattern EMAIL_PATTERN = Pattern.compile("^.*@.*\\..*$"); - /** * Splits userId string into naming part, email part, and comment part * <p/> @@ -70,53 +68,15 @@ public abstract class KeyRing { * http://fiddle.re/t4p6f */ public static UserId splitUserId(final String userId) { - if (!TextUtils.isEmpty(userId)) { - final Matcher matcher = USER_ID_PATTERN.matcher(userId); - if (matcher.matches()) { - String name = matcher.group(1).isEmpty() ? null : matcher.group(1); - String comment = matcher.group(2); - String email = matcher.group(3); - if (comment == null && email == null && name != null && EMAIL_PATTERN.matcher(name).matches()) { - email = name; - name = null; - } - return new UserId(name, email, comment); - } - } - return new UserId(null, null, null); + return OpenPgpUtils.splitUserId(userId); } /** * Returns a composed user id. Returns null if name, email and comment are empty. */ public static String createUserId(UserId userId) { - StringBuilder userIdBuilder = new StringBuilder(); - if (!TextUtils.isEmpty(userId.name)) { - userIdBuilder.append(userId.name); - } - if (!TextUtils.isEmpty(userId.comment)) { - userIdBuilder.append(" ("); - userIdBuilder.append(userId.comment); - userIdBuilder.append(")"); - } - if (!TextUtils.isEmpty(userId.email)) { - userIdBuilder.append(" <"); - userIdBuilder.append(userId.email); - userIdBuilder.append(">"); - } - return userIdBuilder.length() == 0 ? null : userIdBuilder.toString(); + return OpenPgpUtils.createUserId(userId); } - public static class UserId implements Serializable { - public final String name; - public final String email; - public final String comment; - - public UserId(String name, String email, String comment) { - this.name = name; - this.email = email; - this.comment = comment; - } - } } |