diff options
| author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-05-09 15:30:14 +0200 | 
|---|---|---|
| committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-05-27 13:56:28 +0200 | 
| commit | 6415290b2d059752ebcfd74fa2c514aa5e5ef875 (patch) | |
| tree | 78544213c11ac9f80202f24e242d29e32eaa1080 /OpenKeychain/src/main | |
| parent | ce1c3d1a1ee7f8d9b482419801aee494928741d2 (diff) | |
| download | open-keychain-6415290b2d059752ebcfd74fa2c514aa5e5ef875.tar.gz open-keychain-6415290b2d059752ebcfd74fa2c514aa5e5ef875.tar.bz2 open-keychain-6415290b2d059752ebcfd74fa2c514aa5e5ef875.zip  | |
introduce new SaveKeyringParcel
Diffstat (limited to 'OpenKeychain/src/main')
| -rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java | 113 | 
1 files changed, 113 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java new file mode 100644 index 000000000..fffcdacc8 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -0,0 +1,113 @@ +package org.sufficientlysecure.keychain.service; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.Serializable; +import java.util.HashMap; + +/** This class is a a transferable representation for a collection of changes + * to be done on a keyring. + * + * This class should include all types of operations supported in the backend. + * + * 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. + * + * 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. + */ +public class SaveKeyringParcel implements Parcelable { + +    // the master key id to be edited +    private final long mMasterKeyId; +    // the key fingerprint, for safety +    private final byte[] mFingerprint; + +    public String newPassphrase; + +    public String[] addUserIds; +    public SubkeyAdd[] addSubKeys; + +    public HashMap<Long, SubkeyChange> changeSubKeys; +    public String changePrimaryUserId; + +    public String[] revokeUserIds; +    public long[] revokeSubKeys; + +    public SaveKeyringParcel(long masterKeyId, byte[] fingerprint) { +        mMasterKeyId = masterKeyId; +        mFingerprint = fingerprint; +    } + +    // performance gain for using Parcelable here would probably be negligible, +    // use Serializable instead. +    public static class SubkeyAdd implements Serializable { +        public final int mKeysize; +        public final int mFlags; +        public final Long mExpiry; +        public SubkeyAdd(int keysize, int flags, long expiry) { +            mKeysize = keysize; +            mFlags = flags; +            mExpiry = expiry; +        } +    } + +    public static class SubkeyChange implements Serializable { +        public final long mKeyId; +        public final Integer mFlags; +        public final Long mExpiry; +        public SubkeyChange(long keyId, int flags, long expiry) { +            mKeyId = keyId; +            mFlags = flags; +            mExpiry = expiry; +        } +    } + +    public SaveKeyringParcel(Parcel source) { +        mMasterKeyId = source.readLong(); +        mFingerprint = source.createByteArray(); + +        addUserIds = source.createStringArray(); +        addSubKeys = (SubkeyAdd[]) source.readSerializable(); + +        changeSubKeys = (HashMap<Long,SubkeyChange>) source.readSerializable(); +        changePrimaryUserId = source.readString(); + +        revokeUserIds = source.createStringArray(); +        revokeSubKeys = source.createLongArray(); +    } + +    @Override +    public void writeToParcel(Parcel destination, int flags) { +        destination.writeLong(mMasterKeyId); +        destination.writeByteArray(mFingerprint); + +        destination.writeStringArray(addUserIds); +        destination.writeSerializable(addSubKeys); + +        destination.writeSerializable(changeSubKeys); +        destination.writeString(changePrimaryUserId); + +        destination.writeStringArray(revokeUserIds); +        destination.writeLongArray(revokeSubKeys); +    } + +    public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() { +        public SaveKeyringParcel createFromParcel(final Parcel source) { +            return new SaveKeyringParcel(source); +        } + +        public SaveKeyringParcel[] newArray(final int size) { +            return new SaveKeyringParcel[size]; +        } +    }; + +    @Override +    public int describeContents() { +        return 0; +    } + +}  | 
