From a655664c0bd177278826720dbac6b22f4e9e1cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 16 Mar 2015 13:54:01 +0100 Subject: [PATCH] object oriented split user id --- .../keyimport/ImportKeysListEntry.java | 18 +++--- .../keychain/pgp/KeyRing.java | 64 +++++++++---------- .../remote/ui/AccountSettingsFragment.java | 6 +- .../remote/ui/SelectSignKeyIdActivity.java | 6 +- .../keychain/ui/CertifyKeyFragment.java | 7 +- .../keychain/ui/CreateKeyFinalFragment.java | 4 +- .../keychain/ui/DecryptFragment.java | 10 +-- .../keychain/ui/EditKeyFragment.java | 2 +- .../keychain/ui/EncryptFilesActivity.java | 6 +- .../keychain/ui/EncryptTextActivity.java | 7 +- .../keychain/ui/KeyListFragment.java | 10 +-- .../keychain/ui/PassphraseDialogActivity.java | 6 +- .../keychain/ui/ViewKeyActivity.java | 6 +- .../keychain/ui/ViewKeyAdvActivity.java | 6 +- .../keychain/ui/ViewKeyAdvCertsFragment.java | 6 +- .../ui/adapter/ImportKeysAdapter.java | 12 ++-- .../ui/adapter/MultiUserIdsAdapter.java | 21 +++--- .../ui/adapter/SelectKeyCursorAdapter.java | 10 +-- .../keychain/ui/adapter/UserIdsAdapter.java | 14 ++-- .../ui/adapter/UserIdsAddedAdapter.java | 14 ++-- .../ui/dialog/AddUserIdDialogFragment.java | 4 +- .../ui/dialog/DeleteKeyDialogFragment.java | 6 +- .../ui/widget/EncryptKeyCompletionView.java | 14 ++-- .../keychain/ui/widget/KeySpinner.java | 7 +- .../keychain/util/ContactHelper.java | 21 +++--- extern/openpgp-api-lib | 2 +- 26 files changed, 140 insertions(+), 149 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java index 7dac8b1e0..bb86d272f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java @@ -307,24 +307,22 @@ public class ImportKeysListEntry implements Serializable, Parcelable { public void updateMergedUserIds() { mMergedUserIds = new HashMap<>(); for (String userId : mUserIds) { - String[] userIdSplit = KeyRing.splitUserId(userId); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); // TODO: comment field? - // name - if (userIdSplit[0] != null) { - // email - if (userIdSplit[1] != null) { - if (!mMergedUserIds.containsKey(userIdSplit[0])) { + if (userIdSplit.name != null) { + if (userIdSplit.email != null) { + if (!mMergedUserIds.containsKey(userIdSplit.name)) { HashSet emails = new HashSet<>(); - emails.add(userIdSplit[1]); - mMergedUserIds.put(userIdSplit[0], emails); + emails.add(userIdSplit.email); + mMergedUserIds.put(userIdSplit.name, emails); } else { - mMergedUserIds.get(userIdSplit[0]).add(userIdSplit[1]); + mMergedUserIds.get(userIdSplit.name).add(userIdSplit.email); } } else { // name only - mMergedUserIds.put(userIdSplit[0], new HashSet()); + mMergedUserIds.put(userIdSplit.name, new HashSet()); } } else { // fallback 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 26375219b..eb1f93a8b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java @@ -44,7 +44,7 @@ public abstract class KeyRing { abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException; - public String[] getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { + public UserId getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { return splitUserId(getPrimaryUserIdWithFallback()); } @@ -62,35 +62,21 @@ public abstract class KeyRing { /** * Splits userId string into naming part, email part, and comment part + *

+ * User ID matching: + * http://fiddle.re/t4p6f * * @param userId - * @return array with naming (0), email (1), comment (2) + * @return theParsedUserInfo */ - public static String[] splitUserId(String userId) { - String[] result = new String[]{null, null, null}; - - if (userId == null || userId.equals("")) { - return result; + public static UserId splitUserId(final String userId) { + if (!TextUtils.isEmpty(userId)) { + final Matcher matcher = USER_ID_PATTERN.matcher(userId); + if (matcher.matches()) { + return new UserId(matcher.group(1), matcher.group(3), matcher.group(2)); + } } - - /* - * User ID matching: - * http://fiddle.re/t4p6f - * - * test cases: - * "Max Mustermann (this is a comment) " - * "Max Mustermann " - * "Max Mustermann (this is a comment)" - * "Max Mustermann [this is nothing]" - */ - Matcher matcher = USER_ID_PATTERN.matcher(userId); - if (matcher.matches()) { - result[0] = matcher.group(1); - result[1] = matcher.group(3); - result[2] = matcher.group(2); - } - - return result; + return new UserId(null, null, null); } /** @@ -101,16 +87,28 @@ public abstract class KeyRing { * @param comment * @return */ - public static String createUserId(String name, String email, String comment) { - String userId = name; // consider name a required value - if (userId != null && !TextUtils.isEmpty(comment)) { - userId += " (" + comment + ")"; + public static String createUserId(UserId userId) { + String userIdString = userId.name; // consider name a required value + if (userIdString != null && !TextUtils.isEmpty(userId.comment)) { + userIdString += " (" + userId.comment + ")"; } - if (userId != null && !TextUtils.isEmpty(email)) { - userId += " <" + email + ">"; + if (userIdString != null && !TextUtils.isEmpty(userId.email)) { + userIdString += " <" + userId.email + ">"; } - return userId; + return userIdString; + } + + public static class UserId { + 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; + } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java index 4bb64bcaa..81181d61d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java @@ -92,11 +92,11 @@ public class AccountSettingsFragment extends Fragment { } private void createKey() { - String[] userId = KeyRing.splitUserId(mAccSettings.getAccountName()); + KeyRing.UserId userId = KeyRing.splitUserId(mAccSettings.getAccountName()); Intent intent = new Intent(getActivity(), CreateKeyActivity.class); - intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId[0]); - intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId[1]); + intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId.name); + intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId.email); startActivityForResult(intent, REQUEST_CODE_CREATE_KEY); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java index b3096ef99..98a44466d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java @@ -96,11 +96,11 @@ public class SelectSignKeyIdActivity extends BaseActivity { } private void createKey(String userId) { - String[] userIdSplit = KeyRing.splitUserId(userId); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); Intent intent = new Intent(this, CreateKeyActivity.class); - intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit[0]); - intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit[1]); + intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit.name); + intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit.email); startActivityForResult(intent, REQUEST_CODE_CREATE_KEY); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index 1e1bd32c1..9cb4e5f65 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -31,7 +31,6 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.Parcel; -import android.os.Parcelable; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; @@ -247,14 +246,14 @@ public class CertifyKeyFragment extends LoaderFragment while (!data.isAfterLast()) { long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String userId = data.getString(INDEX_USER_ID); - String[] pieces = KeyRing.splitUserId(userId); + KeyRing.UserId pieces = KeyRing.splitUserId(userId); // Two cases: boolean grouped = masterKeyId == lastMasterKeyId; - boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces[0]); + boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name); // Remember for next loop - lastName = pieces[0]; + lastName = pieces.name; Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped")); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index ae42c891d..4871b5ae2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -186,12 +186,12 @@ public class CreateKeyFinalFragment extends Fragment { Algorithm.RSA, 4096, null, KeyFlags.SIGN_DATA, 0L)); mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( Algorithm.RSA, 4096, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L)); - String userId = KeyRing.createUserId(mName, mEmail, null); + String userId = KeyRing.createUserId(new KeyRing.UserId(mName, mEmail, null)); mSaveKeyringParcel.mAddUserIds.add(userId); mSaveKeyringParcel.mChangePrimaryUserId = userId; if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) { for (String email : mAdditionalEmails) { - String thisUserId = KeyRing.createUserId(mName, email, null); + String thisUserId = KeyRing.createUserId(new KeyRing.UserId(mName, email, null)); mSaveKeyringParcel.mAddUserIds.add(thisUserId); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 60103f344..513300cc5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -128,14 +128,14 @@ public abstract class DecryptFragment extends Fragment { mSignatureKeyId = signatureResult.getKeyId(); String userId = signatureResult.getPrimaryUserId(); - String[] userIdSplit = KeyRing.splitUserId(userId); - if (userIdSplit[0] != null) { - mSignatureName.setText(userIdSplit[0]); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); + if (userIdSplit.name != null) { + mSignatureName.setText(userIdSplit.name); } else { mSignatureName.setText(R.string.user_id_no_name); } - if (userIdSplit[1] != null) { - mSignatureEmail.setText(userIdSplit[1]); + if (userIdSplit.email != null) { + mSignatureEmail.setText(userIdSplit.email); } else { mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), mSignatureKeyId)); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 8b9323f19..8d16fe47e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -545,7 +545,7 @@ public class EditKeyFragment extends LoaderFragment implements Messenger messenger = new Messenger(returnHandler); // pre-fill out primary name - String predefinedName = KeyRing.splitUserId(mPrimaryUserId)[0]; + String predefinedName = KeyRing.splitUserId(mPrimaryUserId).name; AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger, predefinedName); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java index 416ddcb3f..fa7717726 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java @@ -273,9 +273,9 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi if (!isModeSymmetric() && mEncryptionUserIds != null) { Set users = new HashSet<>(); for (String user : mEncryptionUserIds) { - String[] userId = KeyRing.splitUserId(user); - if (userId[1] != null) { - users.add(userId[1]); + KeyRing.UserId userId = KeyRing.splitUserId(user); + if (userId.email != null) { + users.add(userId.email); } } sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()])); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java index cd11a60c9..d3dfd73df 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java @@ -36,7 +36,6 @@ import org.sufficientlysecure.keychain.pgp.PgpConstants; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.ShareHelper; import java.util.ArrayList; @@ -253,9 +252,9 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv if (!isModeSymmetric() && mEncryptionUserIds != null) { Set users = new HashSet<>(); for (String user : mEncryptionUserIds) { - String[] userId = KeyRing.splitUserId(user); - if (userId[1] != null) { - users.add(userId[1]); + KeyRing.UserId userId = KeyRing.splitUserId(user); + if (userId.email != null) { + users.add(userId.email); } } // pass trough email addresses as extra for email applications diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 8c34efba2..4b604add8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -688,14 +688,14 @@ public class KeyListFragment extends LoaderFragment { // set name and stuff, common to both key types String userId = cursor.getString(INDEX_USER_ID); - String[] userIdSplit = KeyRing.splitUserId(userId); - if (userIdSplit[0] != null) { - h.mMainUserId.setText(highlighter.highlight(userIdSplit[0])); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); + if (userIdSplit.name != null) { + h.mMainUserId.setText(highlighter.highlight(userIdSplit.name)); } else { h.mMainUserId.setText(R.string.user_id_no_name); } - if (userIdSplit[1] != null) { - h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); + if (userIdSplit.email != null) { + h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit.email)); h.mMainUserIdRest.setVisibility(View.VISIBLE); } else { h.mMainUserIdRest.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index bb669f6b8..48509710a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -211,9 +211,9 @@ public class PassphraseDialogActivity extends FragmentActivity { // the catch clause doesn't return. try { String mainUserId = mSecretRing.getPrimaryUserIdWithFallback(); - String[] mainUserIdSplit = KeyRing.splitUserId(mainUserId); - if (mainUserIdSplit[0] != null) { - userId = mainUserIdSplit[0]; + KeyRing.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId); + if (mainUserIdSplit.name != null) { + userId = mainUserIdSplit.name; } else { userId = getString(R.string.user_id_no_name); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index b25f6bbf2..13a5ac269 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -841,9 +841,9 @@ public class ViewKeyActivity extends BaseActivity implements case LOADER_ID_UNIFIED: { if (data.moveToFirst()) { // get name, email, and comment from USER_ID - String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); - if (mainUserId[0] != null) { - mName.setText(mainUserId[0]); + KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); + if (mainUserId.name != null) { + mName.setText(mainUserId.name); } else { mName.setText(R.string.user_id_no_name); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index 0654f0c9a..f17d6e0fd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -197,9 +197,9 @@ public class ViewKeyAdvActivity extends BaseActivity implements case LOADER_ID_UNIFIED: { if (data.moveToFirst()) { // get name, email, and comment from USER_ID - String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); - if (mainUserId[0] != null) { - setTitle(mainUserId[0]); + KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); + if (mainUserId.name != null) { + setTitle(mainUserId.name); } else { setTitle(R.string.user_id_no_name); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvCertsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvCertsFragment.java index 90d7a400f..f5c8a87b1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvCertsFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvCertsFragment.java @@ -237,9 +237,9 @@ public class ViewKeyAdvCertsFragment extends LoaderFragment implements TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus); String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), cursor.getLong(mIndexSignerKeyId)); - String[] userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId)); - if (userId[0] != null) { - wSignerName.setText(userId[0]); + KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId)); + if (userId.name != null) { + wSignerName.setText(userId.name); } else { wSignerName.setText(R.string.user_id_no_name); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 429feb075..db88de676 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -140,25 +140,25 @@ public class ImportKeysAdapter extends ArrayAdapter { // main user id String userId = entry.getUserIds().get(0); - String[] userIdSplit = KeyRing.splitUserId(userId); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); // name - if (userIdSplit[0] != null) { + if (userIdSplit.name != null) { // show red user id if it is a secret key if (entry.isSecretKey()) { holder.mainUserId.setText(mActivity.getString(R.string.secret_key) - + " " + userIdSplit[0]); + + " " + userIdSplit.name); } else { - holder.mainUserId.setText(highlighter.highlight(userIdSplit[0])); + holder.mainUserId.setText(highlighter.highlight(userIdSplit.name)); } } else { holder.mainUserId.setText(R.string.user_id_no_name); } // email - if (userIdSplit[1] != null) { + if (userIdSplit.email != null) { holder.mainUserIdRest.setVisibility(View.VISIBLE); - holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); + holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email)); } else { holder.mainUserIdRest.setVisibility(View.GONE); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/MultiUserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/MultiUserIdsAdapter.java index 5a0782e54..028f0fc9c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/MultiUserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/MultiUserIdsAdapter.java @@ -33,7 +33,6 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import java.util.ArrayList; @@ -83,9 +82,9 @@ public class MultiUserIdsAdapter extends CursorAdapter { { // first one String userId = uids.get(0); - String[] splitUserId = KeyRing.splitUserId(userId); - if (splitUserId[0] != null) { - vName.setText(splitUserId[0]); + KeyRing.UserId splitUserId = KeyRing.splitUserId(userId); + if (splitUserId.name != null) { + vName.setText(splitUserId.name); } else { vName.setText(R.string.user_id_no_name); } @@ -93,9 +92,9 @@ public class MultiUserIdsAdapter extends CursorAdapter { if (isHeader == 1) { vHeaderId.setVisibility(View.VISIBLE); String message; - if (splitUserId[0] != null) { + if (splitUserId.name != null) { message = mContext.getString(R.string.section_uids_to_certify) + - splitUserId[0]; + splitUserId.name; } else { message = mContext.getString(R.string.section_uids_to_certify) + context.getString(R.string.user_id_no_name); @@ -108,13 +107,13 @@ public class MultiUserIdsAdapter extends CursorAdapter { StringBuilder lines = new StringBuilder(); for (String uid : uids) { - String[] splitUserId = KeyRing.splitUserId(uid); - if (splitUserId[1] == null) { + KeyRing.UserId splitUserId = KeyRing.splitUserId(uid); + if (splitUserId.email == null) { continue; } - lines.append(splitUserId[1]); - if (splitUserId[2] != null) { - lines.append(" (").append(splitUserId[2]).append(")"); + lines.append(splitUserId.email); + if (splitUserId.comment != null) { + lines.append(" (").append(splitUserId.comment).append(")"); } lines.append('\n'); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java index 892e30a54..3308a4500 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java @@ -122,16 +122,16 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { ViewHolderItem h = (ViewHolderItem) view.getTag(); String userId = cursor.getString(mIndexUserId); - String[] userIdSplit = KeyRing.splitUserId(userId); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); - if (userIdSplit[0] != null) { - h.mainUserId.setText(highlighter.highlight(userIdSplit[0])); + if (userIdSplit.name != null) { + h.mainUserId.setText(highlighter.highlight(userIdSplit.name)); } else { h.mainUserId.setText(R.string.user_id_no_name); } - if (userIdSplit[1] != null) { + if (userIdSplit.email != null) { h.mainUserIdRest.setVisibility(View.VISIBLE); - h.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); + h.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email)); } else { h.mainUserIdRest.setVisibility(View.GONE); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index 3486f1516..d1103ac1f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -72,20 +72,20 @@ public class UserIdsAdapter extends UserAttributesAdapter { vDeleteButton.setVisibility(View.GONE); // not used String userId = cursor.getString(INDEX_USER_ID); - String[] splitUserId = KeyRing.splitUserId(userId); - if (splitUserId[0] != null) { - vName.setText(splitUserId[0]); + KeyRing.UserId splitUserId = KeyRing.splitUserId(userId); + if (splitUserId.name != null) { + vName.setText(splitUserId.name); } else { vName.setText(R.string.user_id_no_name); } - if (splitUserId[1] != null) { - vAddress.setText(splitUserId[1]); + if (splitUserId.email != null) { + vAddress.setText(splitUserId.email); vAddress.setVisibility(View.VISIBLE); } else { vAddress.setVisibility(View.GONE); } - if (splitUserId[2] != null) { - vComment.setText(splitUserId[2]); + if (splitUserId.comment != null) { + vComment.setText(splitUserId.comment); vComment.setVisibility(View.VISIBLE); } else { vComment.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java index 970855c77..c7197b46d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java @@ -92,20 +92,20 @@ public class UserIdsAddedAdapter extends ArrayAdapter { // save reference to model item holder.mModel = getItem(position); - String[] splitUserId = KeyRing.splitUserId(holder.mModel); - if (splitUserId[0] != null) { - holder.vName.setText(splitUserId[0]); + KeyRing.UserId splitUserId = KeyRing.splitUserId(holder.mModel); + if (splitUserId.name != null) { + holder.vName.setText(splitUserId.name); } else { holder.vName.setText(R.string.user_id_no_name); } - if (splitUserId[1] != null) { - holder.vAddress.setText(splitUserId[1]); + if (splitUserId.email != null) { + holder.vAddress.setText(splitUserId.email); holder.vAddress.setVisibility(View.VISIBLE); } else { holder.vAddress.setVisibility(View.GONE); } - if (splitUserId[2] != null) { - holder.vComment.setText(splitUserId[2]); + if (splitUserId.comment != null) { + holder.vComment.setText(splitUserId.comment); holder.vComment.setVisibility(View.VISIBLE); } else { holder.vComment.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java index 5dd675fd3..fe4ba0262 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java @@ -100,8 +100,8 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA // return new user id back to activity Bundle data = new Bundle(); - String userId = KeyRing.createUserId(mName.getText().toString(), - mEmail.getText().toString(), mComment.getText().toString()); + String userId = KeyRing.createUserId(new KeyRing.UserId(mName.getText().toString(), + mEmail.getText().toString(), mComment.getText().toString())); data.putString(MESSAGE_DATA_USER_ID, userId); sendMessageToHandler(MESSAGE_OKAY, data); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteKeyDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteKeyDialogFragment.java index 20f20c32e..f512ecca2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteKeyDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteKeyDialogFragment.java @@ -100,9 +100,9 @@ public class DeleteKeyDialogFragment extends DialogFragment { } ); String name; - String[] mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID)); - if (mainUserId[0] != null) { - name = mainUserId[0]; + KeyRing.UserId mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID)); + if (mainUserId.name != null) { + name = mainUserId.name; } else { name = getString(R.string.user_id_no_name); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 94a321f29..ceace1d26 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -184,7 +184,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { public class EncryptionKey { private String mUserIdFull; - private String[] mUserId; + private KeyRing.UserId mUserId; private long mKeyId; private boolean mHasDuplicate; private Date mCreation; @@ -222,23 +222,23 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { } public String getPrimary() { - if (mUserId[0] != null) { - return mUserId[0]; + if (mUserId.name != null) { + return mUserId.name; } else { - return mUserId[1]; + return mUserId.email; } } public String getSecondary() { - if (mUserId[1] != null) { - return mUserId[1]; + if (mUserId.email != null) { + return mUserId.email; } else { return getCreationDate(); } } public String getTertiary() { - if (mUserId[0] != null) { + if (mUserId.name != null) { return getCreationDate(); } else { return null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java index 226588aaa..2c75c3a7d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java @@ -39,7 +39,6 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import java.util.Calendar; @@ -162,9 +161,9 @@ public abstract class KeySpinner extends TintSpinner implements LoaderManager.Lo TextView vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email); TextView vDuplicate = (TextView) view.findViewById(R.id.keyspinner_duplicate); - String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId)); - vKeyName.setText(userId[2] == null ? userId[0] : (userId[0] + " (" + userId[2] + ")")); - vKeyEmail.setText(userId[1]); + KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexUserId)); + vKeyName.setText(userId.name); + vKeyEmail.setText(userId.email); boolean duplicate = cursor.getLong(mIndexDuplicate) > 0; if (duplicate) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 6efc0a5ea..894a7d0d9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -37,7 +37,6 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import java.io.InputStream; import java.util.ArrayList; @@ -447,7 +446,7 @@ public class ContactHelper { if (cursor != null) { while (cursor.moveToNext()) { long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID); - String[] userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID)); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID)); boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0; boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0; @@ -470,19 +469,19 @@ public class ContactHelper { if (rawContactId != -1) { deleteRawContactById(resolver, rawContactId); } - } else if (userIdSplit[0] != null) { + } else if (userIdSplit.name != null) { // Create a new rawcontact with corresponding key if it does not exist yet if (rawContactId == -1) { Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId); insertContact(ops, context, masterKeyId); - writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit[0]); + writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit.name); } // We always update the display name (which is derived from primary user id) // and email addresses from user id - writeContactDisplayName(ops, rawContactId, userIdSplit[0]); + writeContactDisplayName(ops, rawContactId, userIdSplit.name); writeContactEmail(ops, resolver, rawContactId, masterKeyId); try { resolver.applyBatch(ContactsContract.AUTHORITY, ops); @@ -521,9 +520,9 @@ public class ContactHelper { long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID); boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0; boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; - String[] userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID)); + KeyRing.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID)); - if (!isExpired && !isRevoked && userIdSplit[0] != null) { + if (!isExpired && !isRevoked && userIdSplit.name != null) { // if expired or revoked will not be removed from keysToDelete or inserted // into main profile ("me" contact) boolean existsInMainProfile = keysToDelete.remove(masterKeyId); @@ -534,7 +533,7 @@ public class ContactHelper { ArrayList ops = new ArrayList<>(); insertMainProfileRawContact(ops, masterKeyId); - writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit[0]); + writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit.name); try { resolver.applyBatch(ContactsContract.AUTHORITY, ops); @@ -776,14 +775,14 @@ public class ContactHelper { null, null); if (ids != null) { while (ids.moveToNext()) { - String[] userId = KeyRing.splitUserId(ids.getString(0)); - if (userId[1] != null) { + KeyRing.UserId userId = KeyRing.splitUserId(ids.getString(0)); + if (userId.email != null) { ops.add(referenceRawContact( ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI), rawContactId) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.Email.DATA, userId[1]) + .withValue(ContactsContract.CommonDataKinds.Email.DATA, userId.email) .build()); } } diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index bc177ed5e..10be5948d 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit bc177ed5e3f110cf372d6303c8e9d21e46fc76d2 +Subproject commit 10be5948d68bb5e80aed77fdf93cada598ee7667