mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
object oriented split user id
This commit is contained in:
parent
0e71fcd638
commit
a655664c0b
@ -307,24 +307,22 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
public void updateMergedUserIds() {
|
public void updateMergedUserIds() {
|
||||||
mMergedUserIds = new HashMap<>();
|
mMergedUserIds = new HashMap<>();
|
||||||
for (String userId : mUserIds) {
|
for (String userId : mUserIds) {
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
// TODO: comment field?
|
// TODO: comment field?
|
||||||
|
|
||||||
// name
|
if (userIdSplit.name != null) {
|
||||||
if (userIdSplit[0] != null) {
|
if (userIdSplit.email != null) {
|
||||||
// email
|
if (!mMergedUserIds.containsKey(userIdSplit.name)) {
|
||||||
if (userIdSplit[1] != null) {
|
|
||||||
if (!mMergedUserIds.containsKey(userIdSplit[0])) {
|
|
||||||
HashSet<String> emails = new HashSet<>();
|
HashSet<String> emails = new HashSet<>();
|
||||||
emails.add(userIdSplit[1]);
|
emails.add(userIdSplit.email);
|
||||||
mMergedUserIds.put(userIdSplit[0], emails);
|
mMergedUserIds.put(userIdSplit.name, emails);
|
||||||
} else {
|
} else {
|
||||||
mMergedUserIds.get(userIdSplit[0]).add(userIdSplit[1]);
|
mMergedUserIds.get(userIdSplit.name).add(userIdSplit.email);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// name only
|
// name only
|
||||||
mMergedUserIds.put(userIdSplit[0], new HashSet<String>());
|
mMergedUserIds.put(userIdSplit.name, new HashSet<String>());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// fallback
|
// fallback
|
||||||
|
@ -44,7 +44,7 @@ public abstract class KeyRing {
|
|||||||
|
|
||||||
abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException;
|
abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException;
|
||||||
|
|
||||||
public String[] getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException {
|
public UserId getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException {
|
||||||
return splitUserId(getPrimaryUserIdWithFallback());
|
return splitUserId(getPrimaryUserIdWithFallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,35 +62,21 @@ public abstract class KeyRing {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits userId string into naming part, email part, and comment part
|
* Splits userId string into naming part, email part, and comment part
|
||||||
*
|
* <p/>
|
||||||
* @param userId
|
|
||||||
* @return array with naming (0), email (1), comment (2)
|
|
||||||
*/
|
|
||||||
public static String[] splitUserId(String userId) {
|
|
||||||
String[] result = new String[]{null, null, null};
|
|
||||||
|
|
||||||
if (userId == null || userId.equals("")) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* User ID matching:
|
* User ID matching:
|
||||||
* http://fiddle.re/t4p6f
|
* http://fiddle.re/t4p6f
|
||||||
*
|
*
|
||||||
* test cases:
|
* @param userId
|
||||||
* "Max Mustermann (this is a comment) <max@example.com>"
|
* @return theParsedUserInfo
|
||||||
* "Max Mustermann <max@example.com>"
|
|
||||||
* "Max Mustermann (this is a comment)"
|
|
||||||
* "Max Mustermann [this is nothing]"
|
|
||||||
*/
|
*/
|
||||||
Matcher matcher = USER_ID_PATTERN.matcher(userId);
|
public static UserId splitUserId(final String userId) {
|
||||||
|
if (!TextUtils.isEmpty(userId)) {
|
||||||
|
final Matcher matcher = USER_ID_PATTERN.matcher(userId);
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
result[0] = matcher.group(1);
|
return new UserId(matcher.group(1), matcher.group(3), matcher.group(2));
|
||||||
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
|
* @param comment
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String createUserId(String name, String email, String comment) {
|
public static String createUserId(UserId userId) {
|
||||||
String userId = name; // consider name a required value
|
String userIdString = userId.name; // consider name a required value
|
||||||
if (userId != null && !TextUtils.isEmpty(comment)) {
|
if (userIdString != null && !TextUtils.isEmpty(userId.comment)) {
|
||||||
userId += " (" + comment + ")";
|
userIdString += " (" + userId.comment + ")";
|
||||||
}
|
}
|
||||||
if (userId != null && !TextUtils.isEmpty(email)) {
|
if (userIdString != null && !TextUtils.isEmpty(userId.email)) {
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,11 +92,11 @@ public class AccountSettingsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createKey() {
|
private void createKey() {
|
||||||
String[] userId = KeyRing.splitUserId(mAccSettings.getAccountName());
|
KeyRing.UserId userId = KeyRing.splitUserId(mAccSettings.getAccountName());
|
||||||
|
|
||||||
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
|
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId[0]);
|
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId.name);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId[1]);
|
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId.email);
|
||||||
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
|
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +96,11 @@ public class SelectSignKeyIdActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createKey(String userId) {
|
private void createKey(String userId) {
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
Intent intent = new Intent(this, CreateKeyActivity.class);
|
Intent intent = new Intent(this, CreateKeyActivity.class);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit[0]);
|
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit.name);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit[1]);
|
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit.email);
|
||||||
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
|
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
@ -247,14 +246,14 @@ public class CertifyKeyFragment extends LoaderFragment
|
|||||||
while (!data.isAfterLast()) {
|
while (!data.isAfterLast()) {
|
||||||
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
|
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
|
||||||
String userId = data.getString(INDEX_USER_ID);
|
String userId = data.getString(INDEX_USER_ID);
|
||||||
String[] pieces = KeyRing.splitUserId(userId);
|
KeyRing.UserId pieces = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
// Two cases:
|
// Two cases:
|
||||||
|
|
||||||
boolean grouped = masterKeyId == lastMasterKeyId;
|
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
|
// Remember for next loop
|
||||||
lastName = pieces[0];
|
lastName = pieces.name;
|
||||||
|
|
||||||
Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));
|
Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));
|
||||||
|
|
||||||
|
@ -186,12 +186,12 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
Algorithm.RSA, 4096, null, KeyFlags.SIGN_DATA, 0L));
|
Algorithm.RSA, 4096, null, KeyFlags.SIGN_DATA, 0L));
|
||||||
mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||||
Algorithm.RSA, 4096, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L));
|
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.mAddUserIds.add(userId);
|
||||||
mSaveKeyringParcel.mChangePrimaryUserId = userId;
|
mSaveKeyringParcel.mChangePrimaryUserId = userId;
|
||||||
if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) {
|
if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) {
|
||||||
for (String email : mAdditionalEmails) {
|
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);
|
mSaveKeyringParcel.mAddUserIds.add(thisUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,14 +128,14 @@ public abstract class DecryptFragment extends Fragment {
|
|||||||
mSignatureKeyId = signatureResult.getKeyId();
|
mSignatureKeyId = signatureResult.getKeyId();
|
||||||
|
|
||||||
String userId = signatureResult.getPrimaryUserId();
|
String userId = signatureResult.getPrimaryUserId();
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
if (userIdSplit[0] != null) {
|
if (userIdSplit.name != null) {
|
||||||
mSignatureName.setText(userIdSplit[0]);
|
mSignatureName.setText(userIdSplit.name);
|
||||||
} else {
|
} else {
|
||||||
mSignatureName.setText(R.string.user_id_no_name);
|
mSignatureName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
if (userIdSplit[1] != null) {
|
if (userIdSplit.email != null) {
|
||||||
mSignatureEmail.setText(userIdSplit[1]);
|
mSignatureEmail.setText(userIdSplit.email);
|
||||||
} else {
|
} else {
|
||||||
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), mSignatureKeyId));
|
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), mSignatureKeyId));
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
Messenger messenger = new Messenger(returnHandler);
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
// pre-fill out primary name
|
// pre-fill out primary name
|
||||||
String predefinedName = KeyRing.splitUserId(mPrimaryUserId)[0];
|
String predefinedName = KeyRing.splitUserId(mPrimaryUserId).name;
|
||||||
AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger,
|
AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger,
|
||||||
predefinedName);
|
predefinedName);
|
||||||
|
|
||||||
|
@ -273,9 +273,9 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
|
|||||||
if (!isModeSymmetric() && mEncryptionUserIds != null) {
|
if (!isModeSymmetric() && mEncryptionUserIds != null) {
|
||||||
Set<String> users = new HashSet<>();
|
Set<String> users = new HashSet<>();
|
||||||
for (String user : mEncryptionUserIds) {
|
for (String user : mEncryptionUserIds) {
|
||||||
String[] userId = KeyRing.splitUserId(user);
|
KeyRing.UserId userId = KeyRing.splitUserId(user);
|
||||||
if (userId[1] != null) {
|
if (userId.email != null) {
|
||||||
users.add(userId[1]);
|
users.add(userId.email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
|
sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
|
||||||
|
@ -36,7 +36,6 @@ import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
|||||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
|
||||||
import org.sufficientlysecure.keychain.util.ShareHelper;
|
import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -253,9 +252,9 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
|||||||
if (!isModeSymmetric() && mEncryptionUserIds != null) {
|
if (!isModeSymmetric() && mEncryptionUserIds != null) {
|
||||||
Set<String> users = new HashSet<>();
|
Set<String> users = new HashSet<>();
|
||||||
for (String user : mEncryptionUserIds) {
|
for (String user : mEncryptionUserIds) {
|
||||||
String[] userId = KeyRing.splitUserId(user);
|
KeyRing.UserId userId = KeyRing.splitUserId(user);
|
||||||
if (userId[1] != null) {
|
if (userId.email != null) {
|
||||||
users.add(userId[1]);
|
users.add(userId.email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// pass trough email addresses as extra for email applications
|
// pass trough email addresses as extra for email applications
|
||||||
|
@ -688,14 +688,14 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
{ // set name and stuff, common to both key types
|
{ // set name and stuff, common to both key types
|
||||||
String userId = cursor.getString(INDEX_USER_ID);
|
String userId = cursor.getString(INDEX_USER_ID);
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
if (userIdSplit[0] != null) {
|
if (userIdSplit.name != null) {
|
||||||
h.mMainUserId.setText(highlighter.highlight(userIdSplit[0]));
|
h.mMainUserId.setText(highlighter.highlight(userIdSplit.name));
|
||||||
} else {
|
} else {
|
||||||
h.mMainUserId.setText(R.string.user_id_no_name);
|
h.mMainUserId.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
if (userIdSplit[1] != null) {
|
if (userIdSplit.email != null) {
|
||||||
h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
|
h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
|
||||||
h.mMainUserIdRest.setVisibility(View.VISIBLE);
|
h.mMainUserIdRest.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
h.mMainUserIdRest.setVisibility(View.GONE);
|
h.mMainUserIdRest.setVisibility(View.GONE);
|
||||||
|
@ -211,9 +211,9 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
// the catch clause doesn't return.
|
// the catch clause doesn't return.
|
||||||
try {
|
try {
|
||||||
String mainUserId = mSecretRing.getPrimaryUserIdWithFallback();
|
String mainUserId = mSecretRing.getPrimaryUserIdWithFallback();
|
||||||
String[] mainUserIdSplit = KeyRing.splitUserId(mainUserId);
|
KeyRing.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
|
||||||
if (mainUserIdSplit[0] != null) {
|
if (mainUserIdSplit.name != null) {
|
||||||
userId = mainUserIdSplit[0];
|
userId = mainUserIdSplit.name;
|
||||||
} else {
|
} else {
|
||||||
userId = getString(R.string.user_id_no_name);
|
userId = getString(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
@ -841,9 +841,9 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
case LOADER_ID_UNIFIED: {
|
case LOADER_ID_UNIFIED: {
|
||||||
if (data.moveToFirst()) {
|
if (data.moveToFirst()) {
|
||||||
// get name, email, and comment from USER_ID
|
// get name, email, and comment from USER_ID
|
||||||
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
|
KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
|
||||||
if (mainUserId[0] != null) {
|
if (mainUserId.name != null) {
|
||||||
mName.setText(mainUserId[0]);
|
mName.setText(mainUserId.name);
|
||||||
} else {
|
} else {
|
||||||
mName.setText(R.string.user_id_no_name);
|
mName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
@ -197,9 +197,9 @@ public class ViewKeyAdvActivity extends BaseActivity implements
|
|||||||
case LOADER_ID_UNIFIED: {
|
case LOADER_ID_UNIFIED: {
|
||||||
if (data.moveToFirst()) {
|
if (data.moveToFirst()) {
|
||||||
// get name, email, and comment from USER_ID
|
// get name, email, and comment from USER_ID
|
||||||
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
|
KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
|
||||||
if (mainUserId[0] != null) {
|
if (mainUserId.name != null) {
|
||||||
setTitle(mainUserId[0]);
|
setTitle(mainUserId.name);
|
||||||
} else {
|
} else {
|
||||||
setTitle(R.string.user_id_no_name);
|
setTitle(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
@ -237,9 +237,9 @@ public class ViewKeyAdvCertsFragment extends LoaderFragment implements
|
|||||||
TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus);
|
TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus);
|
||||||
|
|
||||||
String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), cursor.getLong(mIndexSignerKeyId));
|
String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), cursor.getLong(mIndexSignerKeyId));
|
||||||
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
|
KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
|
||||||
if (userId[0] != null) {
|
if (userId.name != null) {
|
||||||
wSignerName.setText(userId[0]);
|
wSignerName.setText(userId.name);
|
||||||
} else {
|
} else {
|
||||||
wSignerName.setText(R.string.user_id_no_name);
|
wSignerName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
@ -140,25 +140,25 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
|
|
||||||
// main user id
|
// main user id
|
||||||
String userId = entry.getUserIds().get(0);
|
String userId = entry.getUserIds().get(0);
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
// name
|
// name
|
||||||
if (userIdSplit[0] != null) {
|
if (userIdSplit.name != null) {
|
||||||
// show red user id if it is a secret key
|
// show red user id if it is a secret key
|
||||||
if (entry.isSecretKey()) {
|
if (entry.isSecretKey()) {
|
||||||
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
|
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
|
||||||
+ " " + userIdSplit[0]);
|
+ " " + userIdSplit.name);
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserId.setText(highlighter.highlight(userIdSplit[0]));
|
holder.mainUserId.setText(highlighter.highlight(userIdSplit.name));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserId.setText(R.string.user_id_no_name);
|
holder.mainUserId.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// email
|
// email
|
||||||
if (userIdSplit[1] != null) {
|
if (userIdSplit.email != null) {
|
||||||
holder.mainUserIdRest.setVisibility(View.VISIBLE);
|
holder.mainUserIdRest.setVisibility(View.VISIBLE);
|
||||||
holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
|
holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserIdRest.setVisibility(View.GONE);
|
holder.mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ import android.widget.TextView;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -83,9 +82,9 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
|||||||
|
|
||||||
{ // first one
|
{ // first one
|
||||||
String userId = uids.get(0);
|
String userId = uids.get(0);
|
||||||
String[] splitUserId = KeyRing.splitUserId(userId);
|
KeyRing.UserId splitUserId = KeyRing.splitUserId(userId);
|
||||||
if (splitUserId[0] != null) {
|
if (splitUserId.name != null) {
|
||||||
vName.setText(splitUserId[0]);
|
vName.setText(splitUserId.name);
|
||||||
} else {
|
} else {
|
||||||
vName.setText(R.string.user_id_no_name);
|
vName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
@ -93,9 +92,9 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
|||||||
if (isHeader == 1) {
|
if (isHeader == 1) {
|
||||||
vHeaderId.setVisibility(View.VISIBLE);
|
vHeaderId.setVisibility(View.VISIBLE);
|
||||||
String message;
|
String message;
|
||||||
if (splitUserId[0] != null) {
|
if (splitUserId.name != null) {
|
||||||
message = mContext.getString(R.string.section_uids_to_certify) +
|
message = mContext.getString(R.string.section_uids_to_certify) +
|
||||||
splitUserId[0];
|
splitUserId.name;
|
||||||
} else {
|
} else {
|
||||||
message = mContext.getString(R.string.section_uids_to_certify) +
|
message = mContext.getString(R.string.section_uids_to_certify) +
|
||||||
context.getString(R.string.user_id_no_name);
|
context.getString(R.string.user_id_no_name);
|
||||||
@ -108,13 +107,13 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
|||||||
|
|
||||||
StringBuilder lines = new StringBuilder();
|
StringBuilder lines = new StringBuilder();
|
||||||
for (String uid : uids) {
|
for (String uid : uids) {
|
||||||
String[] splitUserId = KeyRing.splitUserId(uid);
|
KeyRing.UserId splitUserId = KeyRing.splitUserId(uid);
|
||||||
if (splitUserId[1] == null) {
|
if (splitUserId.email == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lines.append(splitUserId[1]);
|
lines.append(splitUserId.email);
|
||||||
if (splitUserId[2] != null) {
|
if (splitUserId.comment != null) {
|
||||||
lines.append(" (").append(splitUserId[2]).append(")");
|
lines.append(" (").append(splitUserId.comment).append(")");
|
||||||
}
|
}
|
||||||
lines.append('\n');
|
lines.append('\n');
|
||||||
}
|
}
|
||||||
|
@ -122,16 +122,16 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
ViewHolderItem h = (ViewHolderItem) view.getTag();
|
ViewHolderItem h = (ViewHolderItem) view.getTag();
|
||||||
|
|
||||||
String userId = cursor.getString(mIndexUserId);
|
String userId = cursor.getString(mIndexUserId);
|
||||||
String[] userIdSplit = KeyRing.splitUserId(userId);
|
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
if (userIdSplit[0] != null) {
|
if (userIdSplit.name != null) {
|
||||||
h.mainUserId.setText(highlighter.highlight(userIdSplit[0]));
|
h.mainUserId.setText(highlighter.highlight(userIdSplit.name));
|
||||||
} else {
|
} else {
|
||||||
h.mainUserId.setText(R.string.user_id_no_name);
|
h.mainUserId.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
if (userIdSplit[1] != null) {
|
if (userIdSplit.email != null) {
|
||||||
h.mainUserIdRest.setVisibility(View.VISIBLE);
|
h.mainUserIdRest.setVisibility(View.VISIBLE);
|
||||||
h.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
|
h.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
|
||||||
} else {
|
} else {
|
||||||
h.mainUserIdRest.setVisibility(View.GONE);
|
h.mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -72,20 +72,20 @@ public class UserIdsAdapter extends UserAttributesAdapter {
|
|||||||
vDeleteButton.setVisibility(View.GONE); // not used
|
vDeleteButton.setVisibility(View.GONE); // not used
|
||||||
|
|
||||||
String userId = cursor.getString(INDEX_USER_ID);
|
String userId = cursor.getString(INDEX_USER_ID);
|
||||||
String[] splitUserId = KeyRing.splitUserId(userId);
|
KeyRing.UserId splitUserId = KeyRing.splitUserId(userId);
|
||||||
if (splitUserId[0] != null) {
|
if (splitUserId.name != null) {
|
||||||
vName.setText(splitUserId[0]);
|
vName.setText(splitUserId.name);
|
||||||
} else {
|
} else {
|
||||||
vName.setText(R.string.user_id_no_name);
|
vName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
if (splitUserId[1] != null) {
|
if (splitUserId.email != null) {
|
||||||
vAddress.setText(splitUserId[1]);
|
vAddress.setText(splitUserId.email);
|
||||||
vAddress.setVisibility(View.VISIBLE);
|
vAddress.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
vAddress.setVisibility(View.GONE);
|
vAddress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (splitUserId[2] != null) {
|
if (splitUserId.comment != null) {
|
||||||
vComment.setText(splitUserId[2]);
|
vComment.setText(splitUserId.comment);
|
||||||
vComment.setVisibility(View.VISIBLE);
|
vComment.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
vComment.setVisibility(View.GONE);
|
vComment.setVisibility(View.GONE);
|
||||||
|
@ -92,20 +92,20 @@ public class UserIdsAddedAdapter extends ArrayAdapter<String> {
|
|||||||
// save reference to model item
|
// save reference to model item
|
||||||
holder.mModel = getItem(position);
|
holder.mModel = getItem(position);
|
||||||
|
|
||||||
String[] splitUserId = KeyRing.splitUserId(holder.mModel);
|
KeyRing.UserId splitUserId = KeyRing.splitUserId(holder.mModel);
|
||||||
if (splitUserId[0] != null) {
|
if (splitUserId.name != null) {
|
||||||
holder.vName.setText(splitUserId[0]);
|
holder.vName.setText(splitUserId.name);
|
||||||
} else {
|
} else {
|
||||||
holder.vName.setText(R.string.user_id_no_name);
|
holder.vName.setText(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
if (splitUserId[1] != null) {
|
if (splitUserId.email != null) {
|
||||||
holder.vAddress.setText(splitUserId[1]);
|
holder.vAddress.setText(splitUserId.email);
|
||||||
holder.vAddress.setVisibility(View.VISIBLE);
|
holder.vAddress.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.vAddress.setVisibility(View.GONE);
|
holder.vAddress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (splitUserId[2] != null) {
|
if (splitUserId.comment != null) {
|
||||||
holder.vComment.setText(splitUserId[2]);
|
holder.vComment.setText(splitUserId.comment);
|
||||||
holder.vComment.setVisibility(View.VISIBLE);
|
holder.vComment.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.vComment.setVisibility(View.GONE);
|
holder.vComment.setVisibility(View.GONE);
|
||||||
|
@ -100,8 +100,8 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA
|
|||||||
|
|
||||||
// return new user id back to activity
|
// return new user id back to activity
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
String userId = KeyRing.createUserId(mName.getText().toString(),
|
String userId = KeyRing.createUserId(new KeyRing.UserId(mName.getText().toString(),
|
||||||
mEmail.getText().toString(), mComment.getText().toString());
|
mEmail.getText().toString(), mComment.getText().toString()));
|
||||||
data.putString(MESSAGE_DATA_USER_ID, userId);
|
data.putString(MESSAGE_DATA_USER_ID, userId);
|
||||||
sendMessageToHandler(MESSAGE_OKAY, data);
|
sendMessageToHandler(MESSAGE_OKAY, data);
|
||||||
}
|
}
|
||||||
|
@ -100,9 +100,9 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
String name;
|
String name;
|
||||||
String[] mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID));
|
KeyRing.UserId mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID));
|
||||||
if (mainUserId[0] != null) {
|
if (mainUserId.name != null) {
|
||||||
name = mainUserId[0];
|
name = mainUserId.name;
|
||||||
} else {
|
} else {
|
||||||
name = getString(R.string.user_id_no_name);
|
name = getString(R.string.user_id_no_name);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
|
|||||||
|
|
||||||
public class EncryptionKey {
|
public class EncryptionKey {
|
||||||
private String mUserIdFull;
|
private String mUserIdFull;
|
||||||
private String[] mUserId;
|
private KeyRing.UserId mUserId;
|
||||||
private long mKeyId;
|
private long mKeyId;
|
||||||
private boolean mHasDuplicate;
|
private boolean mHasDuplicate;
|
||||||
private Date mCreation;
|
private Date mCreation;
|
||||||
@ -222,23 +222,23 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimary() {
|
public String getPrimary() {
|
||||||
if (mUserId[0] != null) {
|
if (mUserId.name != null) {
|
||||||
return mUserId[0];
|
return mUserId.name;
|
||||||
} else {
|
} else {
|
||||||
return mUserId[1];
|
return mUserId.email;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSecondary() {
|
public String getSecondary() {
|
||||||
if (mUserId[1] != null) {
|
if (mUserId.email != null) {
|
||||||
return mUserId[1];
|
return mUserId.email;
|
||||||
} else {
|
} else {
|
||||||
return getCreationDate();
|
return getCreationDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTertiary() {
|
public String getTertiary() {
|
||||||
if (mUserId[0] != null) {
|
if (mUserId.name != null) {
|
||||||
return getCreationDate();
|
return getCreationDate();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -39,7 +39,6 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.Calendar;
|
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 vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email);
|
||||||
TextView vDuplicate = (TextView) view.findViewById(R.id.keyspinner_duplicate);
|
TextView vDuplicate = (TextView) view.findViewById(R.id.keyspinner_duplicate);
|
||||||
|
|
||||||
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
|
KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
|
||||||
vKeyName.setText(userId[2] == null ? userId[0] : (userId[0] + " (" + userId[2] + ")"));
|
vKeyName.setText(userId.name);
|
||||||
vKeyEmail.setText(userId[1]);
|
vKeyEmail.setText(userId.email);
|
||||||
|
|
||||||
boolean duplicate = cursor.getLong(mIndexDuplicate) > 0;
|
boolean duplicate = cursor.getLong(mIndexDuplicate) > 0;
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
|
@ -37,7 +37,6 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -447,7 +446,7 @@ public class ContactHelper {
|
|||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
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 isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
|
||||||
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
|
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
|
||||||
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
|
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
|
||||||
@ -470,19 +469,19 @@ public class ContactHelper {
|
|||||||
if (rawContactId != -1) {
|
if (rawContactId != -1) {
|
||||||
deleteRawContactById(resolver, rawContactId);
|
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
|
// Create a new rawcontact with corresponding key if it does not exist yet
|
||||||
if (rawContactId == -1) {
|
if (rawContactId == -1) {
|
||||||
Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId);
|
Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId);
|
||||||
|
|
||||||
insertContact(ops, context, 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)
|
// We always update the display name (which is derived from primary user id)
|
||||||
// and email addresses from user id
|
// and email addresses from user id
|
||||||
writeContactDisplayName(ops, rawContactId, userIdSplit[0]);
|
writeContactDisplayName(ops, rawContactId, userIdSplit.name);
|
||||||
writeContactEmail(ops, resolver, rawContactId, masterKeyId);
|
writeContactEmail(ops, resolver, rawContactId, masterKeyId);
|
||||||
try {
|
try {
|
||||||
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
@ -521,9 +520,9 @@ public class ContactHelper {
|
|||||||
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
||||||
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
|
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
|
||||||
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 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
|
// if expired or revoked will not be removed from keysToDelete or inserted
|
||||||
// into main profile ("me" contact)
|
// into main profile ("me" contact)
|
||||||
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
|
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
|
||||||
@ -534,7 +533,7 @@ public class ContactHelper {
|
|||||||
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
||||||
insertMainProfileRawContact(ops, masterKeyId);
|
insertMainProfileRawContact(ops, masterKeyId);
|
||||||
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit[0]);
|
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit.name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
@ -776,14 +775,14 @@ public class ContactHelper {
|
|||||||
null, null);
|
null, null);
|
||||||
if (ids != null) {
|
if (ids != null) {
|
||||||
while (ids.moveToNext()) {
|
while (ids.moveToNext()) {
|
||||||
String[] userId = KeyRing.splitUserId(ids.getString(0));
|
KeyRing.UserId userId = KeyRing.splitUserId(ids.getString(0));
|
||||||
if (userId[1] != null) {
|
if (userId.email != null) {
|
||||||
ops.add(referenceRawContact(
|
ops.add(referenceRawContact(
|
||||||
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI),
|
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI),
|
||||||
rawContactId)
|
rawContactId)
|
||||||
.withValue(ContactsContract.Data.MIMETYPE,
|
.withValue(ContactsContract.Data.MIMETYPE,
|
||||||
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
|
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
|
||||||
.withValue(ContactsContract.CommonDataKinds.Email.DATA, userId[1])
|
.withValue(ContactsContract.CommonDataKinds.Email.DATA, userId.email)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
extern/openpgp-api-lib
vendored
2
extern/openpgp-api-lib
vendored
@ -1 +1 @@
|
|||||||
Subproject commit bc177ed5e3f110cf372d6303c8e9d21e46fc76d2
|
Subproject commit 10be5948d68bb5e80aed77fdf93cada598ee7667
|
Loading…
Reference in New Issue
Block a user