ImportKeys: Integrate more features in ImportKeysListEntry
This commit is contained in:
parent
0325c27987
commit
9bf06e216b
|
@ -160,10 +160,7 @@ public class FacebookKeyserver extends Keyserver {
|
|||
entry.setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
||||
|
||||
entry.setKeyId(key.getKeyId());
|
||||
entry.setKeyIdHex(KeyFormattingUtils.convertKeyIdToHex(key.getKeyId()));
|
||||
|
||||
entry.setFingerprintHex(KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint()));
|
||||
|
||||
entry.setFingerprint(key.getFingerprint());
|
||||
|
||||
try {
|
||||
if (key.isEC()) { // unsupported key format (ECDH or ECDSA)
|
||||
|
|
|
@ -21,7 +21,7 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
||||
|
@ -45,7 +45,6 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
private HashMap<String, HashSet<String>> mMergedUserIds;
|
||||
private ArrayList<Map.Entry<String, HashSet<String>>> mSortedUserIds;
|
||||
|
||||
private long mKeyId;
|
||||
private String mKeyIdHex;
|
||||
private boolean mRevoked;
|
||||
private boolean mExpired;
|
||||
|
@ -55,7 +54,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
private String mCurveOid;
|
||||
private String mAlgorithm;
|
||||
private boolean mSecretKey;
|
||||
private String mPrimaryUserId;
|
||||
private UserId mPrimaryUserId;
|
||||
private String mKeybaseName;
|
||||
private String mFbUsername;
|
||||
private String mQuery;
|
||||
|
@ -68,10 +67,9 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mPrimaryUserId);
|
||||
dest.writeSerializable(mPrimaryUserId);
|
||||
dest.writeStringList(mUserIds);
|
||||
dest.writeSerializable(mMergedUserIds);
|
||||
dest.writeLong(mKeyId);
|
||||
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
||||
dest.writeByte((byte) (mExpired ? 1 : 0));
|
||||
dest.writeInt(mDate == null ? 0 : 1);
|
||||
|
@ -94,11 +92,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
||||
public ImportKeysListEntry createFromParcel(final Parcel source) {
|
||||
ImportKeysListEntry vr = new ImportKeysListEntry();
|
||||
vr.mPrimaryUserId = source.readString();
|
||||
vr.mPrimaryUserId = (UserId) source.readSerializable();
|
||||
vr.mUserIds = new ArrayList<>();
|
||||
source.readStringList(vr.mUserIds);
|
||||
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
||||
vr.mKeyId = source.readLong();
|
||||
vr.mRevoked = source.readByte() == 1;
|
||||
vr.mExpired = source.readByte() == 1;
|
||||
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
||||
|
@ -138,6 +135,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
return mKeyIdHex;
|
||||
}
|
||||
|
||||
public void setKeyIdHex(String keyIdHex) {
|
||||
mKeyIdHex = keyIdHex;
|
||||
}
|
||||
|
||||
public void setKeyId(long keyId) {
|
||||
mKeyIdHex = KeyFormattingUtils.convertKeyIdToHex(keyId);
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return mExpired;
|
||||
}
|
||||
|
@ -146,22 +151,6 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
mExpired = expired;
|
||||
}
|
||||
|
||||
public byte[] getEncodedRing() {
|
||||
return mEncodedRing;
|
||||
}
|
||||
|
||||
public long getKeyId() {
|
||||
return mKeyId;
|
||||
}
|
||||
|
||||
public void setKeyId(long keyId) {
|
||||
mKeyId = keyId;
|
||||
}
|
||||
|
||||
public void setKeyIdHex(String keyIdHex) {
|
||||
mKeyIdHex = keyIdHex;
|
||||
}
|
||||
|
||||
public boolean isRevoked() {
|
||||
return mRevoked;
|
||||
}
|
||||
|
@ -170,6 +159,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
mRevoked = revoked;
|
||||
}
|
||||
|
||||
public boolean isRevokedOrExpired() {
|
||||
return mRevoked || mExpired;
|
||||
}
|
||||
|
||||
public byte[] getEncodedRing() {
|
||||
return mEncodedRing;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return mDate;
|
||||
}
|
||||
|
@ -186,6 +183,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
mFingerprintHex = fingerprintHex;
|
||||
}
|
||||
|
||||
public void setFingerprint(byte[] fingerprint) {
|
||||
mFingerprintHex = KeyFormattingUtils.convertFingerprintToHex(fingerprint);
|
||||
}
|
||||
|
||||
public Integer getBitStrength() {
|
||||
return mBitStrength;
|
||||
}
|
||||
|
@ -214,12 +215,16 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
mSecretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getPrimaryUserId() {
|
||||
public UserId getPrimaryUserId() {
|
||||
return mPrimaryUserId;
|
||||
}
|
||||
|
||||
public void setPrimaryUserId(String uid) {
|
||||
mPrimaryUserId = uid;
|
||||
public void setPrimaryUserId(String userId) {
|
||||
mPrimaryUserId = KeyRing.splitUserId(userId);
|
||||
}
|
||||
|
||||
public void setPrimaryUserId(UserId primaryUserId) {
|
||||
mPrimaryUserId = primaryUserId;
|
||||
}
|
||||
|
||||
public String getKeybaseName() {
|
||||
|
@ -317,27 +322,26 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||
|
||||
mHashCode = key.hashCode();
|
||||
|
||||
mPrimaryUserId = key.getPrimaryUserIdWithFallback();
|
||||
mUserIds = key.getUnorderedUserIds();
|
||||
updateMergedUserIds();
|
||||
|
||||
mKeyId = key.getKeyId();
|
||||
mKeyIdHex = KeyFormattingUtils.convertKeyIdToHex(mKeyId);
|
||||
setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
||||
setKeyId(key.getKeyId());
|
||||
setFingerprint(key.getFingerprint());
|
||||
|
||||
// NOTE: Dont use maybe methods for now, they can be wrong.
|
||||
mRevoked = false; //key.isMaybeRevoked();
|
||||
mExpired = false; //key.isMaybeExpired();
|
||||
mFingerprintHex = KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint());
|
||||
|
||||
mBitStrength = key.getBitStrength();
|
||||
mCurveOid = key.getCurveOid();
|
||||
final int algorithm = key.getAlgorithm();
|
||||
mAlgorithm = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, mBitStrength, mCurveOid);
|
||||
|
||||
setUserIds(key.getUnorderedUserIds());
|
||||
}
|
||||
|
||||
private void updateMergedUserIds() {
|
||||
mMergedUserIds = new HashMap<>();
|
||||
for (String userId : mUserIds) {
|
||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||
UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||
|
||||
// TODO: comment field?
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.databinding.ImportKeysListItemBinding;
|
||||
|
@ -43,7 +42,6 @@ import org.sufficientlysecure.keychain.keyimport.processing.LoaderState;
|
|||
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
|
@ -135,9 +133,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(mActivity);
|
||||
View v = inflater.inflate(R.layout.import_keys_list_item, parent, false);
|
||||
ViewHolder vh = new ViewHolder(v);
|
||||
return vh;
|
||||
return new ViewHolder(inflater.inflate(R.layout.import_keys_list_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,12 +144,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
|
||||
b.setHighlighter(highlighter);
|
||||
|
||||
String userId = entry.getPrimaryUserId();
|
||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||
|
||||
b.setEntry(entry);
|
||||
b.setUserId(userIdSplit.name);
|
||||
b.setUserIdEmail(userIdSplit.email);
|
||||
|
||||
if (entry.isRevoked()) {
|
||||
KeyFormattingUtils.setStatusImage(mActivity, b.status, null,
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ImportUserIdsView extends LinearLayout {
|
|||
uidView.setText(highlighter.highlight(cUserId));
|
||||
uidView.setPadding(0, 0, FormattingUtils.dpToPx(context, 8), 0);
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
if (entry.isRevokedOrExpired()) {
|
||||
uidView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
uidView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||
|
@ -57,7 +57,7 @@ public class ImportUserIdsView extends LinearLayout {
|
|||
FormattingUtils.dpToPx(context, 8), 0);
|
||||
emailView.setText(highlighter.highlight(email));
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
if (entry.isRevokedOrExpired()) {
|
||||
emailView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
emailView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||
|
|
|
@ -95,7 +95,7 @@ public class EmailKeyHelper {
|
|||
Set<ImportKeysListEntry> keys = new HashSet<>();
|
||||
try {
|
||||
for (ImportKeysListEntry key : keyServer.search(mail)) {
|
||||
if (key.isRevoked() || key.isExpired()) continue;
|
||||
if (key.isRevokedOrExpired()) continue;
|
||||
for (String userId : key.getUserIds()) {
|
||||
if (userId.toLowerCase().contains(mail.toLowerCase(Locale.ENGLISH))) {
|
||||
keys.add(key);
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
<variable name="highlighter" type="Highlighter" />
|
||||
|
||||
<variable name="entry" type="ImportKeysListEntry" />
|
||||
<variable name="userId" type="String" />
|
||||
<variable name="userIdEmail" type="String" />
|
||||
</data>
|
||||
|
||||
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
|
@ -61,23 +59,23 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text='@{entry.secretKey ? @string/secret_key + " " + (userId ?? @string/user_id_no_name) : highlighter.highlight(userId ?? @string/user_id_no_name)}'
|
||||
android:text='@{entry.secretKey ? @string/secret_key + " " + (entry.primaryUserId.name ?? @string/user_id_no_name) : highlighter.highlight(entry.primaryUserId.name ?? @string/user_id_no_name)}'
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : (entry.secretKey ? secretColor : standardColor)}" />
|
||||
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : (entry.secretKey ? secretColor : standardColor)}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@{highlighter.highlight(userIdEmail)}"
|
||||
android:text="@{highlighter.highlight(entry.primaryUserId.email)}"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}" />
|
||||
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : standardColor}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}"
|
||||
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : standardColor}"
|
||||
app:keyId='@{entry.keyIdHex ?? ""}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -88,7 +86,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:visibility="@{entry.revoked || entry.expired ? View.VISIBLE : View.GONE}" />
|
||||
android:visibility="@{entry.revokedOrExpired ? View.VISIBLE : View.GONE}" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue