Refactor expiry dialog
This commit is contained in:
@@ -20,19 +20,23 @@ package org.sufficientlysecure.keychain.service;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** This class is a a transferable representation for a collection of changes
|
||||
/**
|
||||
* This class is a a transferable representation for a collection of changes
|
||||
* to be done on a keyring.
|
||||
*
|
||||
* <p/>
|
||||
* This class should include all types of operations supported in the backend.
|
||||
*
|
||||
* <p/>
|
||||
* All changes are done in a differential manner. Besides the two key
|
||||
* identification attributes, all attributes may be null, which indicates no
|
||||
* change to the keyring. This is also the reason why boxed values are used
|
||||
* instead of primitives in the subclasses.
|
||||
*
|
||||
* <p/>
|
||||
* Application of operations in the backend should be fail-fast, which means an
|
||||
* error in any included operation (for example revocation of a non-existent
|
||||
* subkey) will cause the operation as a whole to fail.
|
||||
@@ -82,12 +86,23 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public int mKeysize;
|
||||
public int mFlags;
|
||||
public Long mExpiry;
|
||||
|
||||
public SubkeyAdd(int algorithm, int keysize, int flags, Long expiry) {
|
||||
mAlgorithm = algorithm;
|
||||
mKeysize = keysize;
|
||||
mFlags = flags;
|
||||
mExpiry = expiry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "mAlgorithm: " + mAlgorithm + ", ";
|
||||
out += "mKeysize: " + mKeysize + ", ";
|
||||
out += "mFlags: " + mFlags;
|
||||
out += "mExpiry: " + mExpiry;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubkeyChange implements Serializable {
|
||||
@@ -95,11 +110,46 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public Integer mFlags;
|
||||
// this is a long unix timestamp, in seconds (NOT MILLISECONDS!)
|
||||
public Long mExpiry;
|
||||
|
||||
public SubkeyChange(long keyId) {
|
||||
mKeyId = keyId;
|
||||
}
|
||||
|
||||
public SubkeyChange(long keyId, Integer flags, Long expiry) {
|
||||
mKeyId = keyId;
|
||||
mFlags = flags;
|
||||
mExpiry = expiry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "mKeyId: " + mKeyId + ", ";
|
||||
out += "mFlags: " + mFlags + ", ";
|
||||
out += "mExpiry: " + mExpiry;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
public SubkeyChange getSubkeyChange(long keyId) {
|
||||
for (SubkeyChange subkeyChange : mChangeSubKeys) {
|
||||
if (subkeyChange.mKeyId == keyId) {
|
||||
return subkeyChange;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SubkeyChange getOrCreateSubkeyChange(long keyId) {
|
||||
SubkeyChange foundSubkeyChange = getSubkeyChange(keyId);
|
||||
if (foundSubkeyChange != null) {
|
||||
return foundSubkeyChange;
|
||||
} else {
|
||||
// else, create a new one
|
||||
SubkeyChange newSubkeyChange = new SubkeyChange(keyId);
|
||||
mChangeSubKeys.add(newSubkeyChange);
|
||||
return newSubkeyChange;
|
||||
}
|
||||
}
|
||||
|
||||
public SaveKeyringParcel(Parcel source) {
|
||||
@@ -121,7 +171,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel destination, int flags) {
|
||||
destination.writeInt(mMasterKeyId == null ? 0 : 1);
|
||||
if(mMasterKeyId != null) {
|
||||
if (mMasterKeyId != null) {
|
||||
destination.writeLong(mMasterKeyId);
|
||||
}
|
||||
destination.writeByteArray(mFingerprint);
|
||||
@@ -153,4 +203,16 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "mMasterKeyId: " + mMasterKeyId + "\n";
|
||||
out += "mNewPassphrase: " + mNewPassphrase + "\n";
|
||||
out += "mAddSubKeys: " + mAddSubKeys + "\n";
|
||||
out += "mChangeSubKeys: " + mChangeSubKeys + "\n";
|
||||
out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n";
|
||||
out += "mRevokeUserIds: " + mRevokeUserIds + "\n";
|
||||
out += "mRevokeSubKeys: " + mRevokeSubKeys;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user