mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-17 07:30:14 -05:00
introduce CryptoOperationParcel for nfc data
This commit is contained in:
parent
53d7c1f533
commit
4499caef1e
@ -23,15 +23,17 @@ import android.os.Parcelable;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoOperationParcel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a a transferable representation for a number of keyrings to
|
* This class is a a transferable representation for a number of keyrings to
|
||||||
* be certified.
|
* be certified.
|
||||||
*/
|
*/
|
||||||
public class CertifyActionsParcel implements Parcelable {
|
public class CertifyActionsParcel extends CryptoOperationParcel {
|
||||||
|
|
||||||
// the master key id to certify with
|
// the master key id to certify with
|
||||||
final public long mMasterKeyId;
|
final public long mMasterKeyId;
|
||||||
@ -39,12 +41,15 @@ public class CertifyActionsParcel implements Parcelable {
|
|||||||
|
|
||||||
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
|
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
|
||||||
|
|
||||||
public CertifyActionsParcel(long masterKeyId) {
|
public CertifyActionsParcel(Date operationTime, long masterKeyId) {
|
||||||
|
super(operationTime);
|
||||||
mMasterKeyId = masterKeyId;
|
mMasterKeyId = masterKeyId;
|
||||||
mLevel = CertifyLevel.DEFAULT;
|
mLevel = CertifyLevel.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertifyActionsParcel(Parcel source) {
|
public CertifyActionsParcel(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
mMasterKeyId = source.readLong();
|
mMasterKeyId = source.readLong();
|
||||||
// just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
|
// just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
|
||||||
mLevel = CertifyLevel.values()[source.readInt()];
|
mLevel = CertifyLevel.values()[source.readInt()];
|
||||||
@ -58,6 +63,8 @@ public class CertifyActionsParcel implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel destination, int flags) {
|
public void writeToParcel(Parcel destination, int flags) {
|
||||||
|
super.writeToParcel(destination, flags);
|
||||||
|
|
||||||
destination.writeLong(mMasterKeyId);
|
destination.writeLong(mMasterKeyId);
|
||||||
destination.writeInt(mLevel.ordinal());
|
destination.writeInt(mLevel.ordinal());
|
||||||
|
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package org.sufficientlysecure.keychain.service.input;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
|
||||||
|
/** This is a base class for the input of crypto operations.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class CryptoOperationParcel implements Parcelable {
|
||||||
|
|
||||||
|
Date mOperationTime;
|
||||||
|
|
||||||
|
// this map contains both decrypted session keys and signed hashes to be
|
||||||
|
// used in the crypto operation described by this parcel.
|
||||||
|
HashMap<ByteBuffer,byte[]> mCryptoData;
|
||||||
|
|
||||||
|
protected CryptoOperationParcel(Date operationTime) {
|
||||||
|
mOperationTime = operationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CryptoOperationParcel(Parcel source) {
|
||||||
|
mOperationTime = new Date(source.readLong());
|
||||||
|
|
||||||
|
{
|
||||||
|
int count = source.readInt();
|
||||||
|
mCryptoData = new HashMap<>(count);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
byte[] key = source.createByteArray();
|
||||||
|
byte[] value = source.createByteArray();
|
||||||
|
mCryptoData.put(ByteBuffer.wrap(key), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeLong(mOperationTime.getTime());
|
||||||
|
|
||||||
|
dest.writeInt(mCryptoData.size());
|
||||||
|
for (HashMap.Entry<ByteBuffer,byte[]> entry : mCryptoData.entrySet()) {
|
||||||
|
dest.writeByteArray(entry.getKey().array());
|
||||||
|
dest.writeByteArray(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -66,6 +66,8 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
public class CertifyKeyFragment extends LoaderFragment
|
public class CertifyKeyFragment extends LoaderFragment
|
||||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
@ -368,7 +370,7 @@ public class CertifyKeyFragment extends LoaderFragment
|
|||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
{
|
{
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
CertifyActionsParcel parcel = new CertifyActionsParcel(mSignMasterKeyId);
|
CertifyActionsParcel parcel = new CertifyActionsParcel(new Date(), mSignMasterKeyId);
|
||||||
parcel.mCertifyActions.addAll(certifyActions);
|
parcel.mCertifyActions.addAll(certifyActions);
|
||||||
|
|
||||||
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
|
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
|
||||||
|
Loading…
Reference in New Issue
Block a user