use autovalue for InputDataParcel and SignEncryptParcel
This commit is contained in:
parent
040a5a2006
commit
9d485dfe9f
|
@ -86,8 +86,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
|
|||
PgpSignEncryptData.Builder data = PgpSignEncryptData.builder();
|
||||
data.setSymmetricPassphrase(passphrase);
|
||||
data.setSymmetricEncryptionAlgorithm(OpenKeychainSymmetricKeyAlgorithmTags.AES_128);
|
||||
SignEncryptParcel input = new SignEncryptParcel(data.build());
|
||||
input.setBytes(buf);
|
||||
SignEncryptParcel input = SignEncryptParcel.createSignEncryptParcel(data.build(), buf);
|
||||
encryptResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||
log.add(encryptResult, 1);
|
||||
log.add(LogType.MSG_BENCH_ENC_TIME, 2,
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.content.Context;
|
|||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
|
||||
|
@ -36,13 +35,11 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptInputParcel;
|
|||
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.SecurityTokenSignOperationsBuilder;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
|
||||
|
@ -76,8 +73,6 @@ public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
|
|||
|
||||
SecurityTokenSignOperationsBuilder pendingInputBuilder = null;
|
||||
|
||||
PgpSignEncryptData data = input.getData();
|
||||
|
||||
do {
|
||||
if (checkCancelled()) {
|
||||
log.add(LogType.MSG_OPERATION_CANCELLED, 0);
|
||||
|
@ -86,7 +81,7 @@ public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
|
|||
|
||||
PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mKeyRepository,
|
||||
new ProgressScaler(mProgressable, 100 * count / total, 100 * ++count / total, 100), mCancelled);
|
||||
PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData());
|
||||
PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getSignEncryptData());
|
||||
if (inputBytes != null) {
|
||||
inputParcel.setInputBytes(inputBytes);
|
||||
} else {
|
||||
|
@ -106,7 +101,7 @@ public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
|
|||
}
|
||||
if (pendingInputBuilder == null) {
|
||||
pendingInputBuilder = new SecurityTokenSignOperationsBuilder(requiredInput.mSignatureTime,
|
||||
data.getSignatureMasterKeyId(), data.getSignatureSubKeyId());
|
||||
requiredInput.getMasterKeyId(), requiredInput.getSubKeyId());
|
||||
}
|
||||
pendingInputBuilder.addAll(requiredInput);
|
||||
} else if (!result.success()) {
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
|
||||
/**
|
||||
* This parcel stores the input of one or more PgpSignEncrypt operations.
|
||||
* All operations will use the same general parameters, differing only in
|
||||
|
@ -39,83 +42,65 @@ import java.util.List;
|
|||
* - Once the output uris are empty, there must be exactly one input (uri xor bytes)
|
||||
* left, which will be returned in a byte array as part of the result parcel.
|
||||
*/
|
||||
public class SignEncryptParcel implements Parcelable {
|
||||
@AutoValue
|
||||
public abstract class SignEncryptParcel implements Parcelable {
|
||||
public abstract PgpSignEncryptData getSignEncryptData();
|
||||
public abstract List<Uri> getInputUris();
|
||||
public abstract List<Uri> getOutputUris();
|
||||
@SuppressWarnings("mutable")
|
||||
@Nullable
|
||||
public abstract byte[] getBytes();
|
||||
|
||||
private PgpSignEncryptData data;
|
||||
|
||||
public ArrayList<Uri> mInputUris = new ArrayList<>();
|
||||
public ArrayList<Uri> mOutputUris = new ArrayList<>();
|
||||
public byte[] mBytes;
|
||||
|
||||
public SignEncryptParcel(PgpSignEncryptData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public SignEncryptParcel(Parcel src) {
|
||||
mInputUris = src.createTypedArrayList(Uri.CREATOR);
|
||||
mOutputUris = src.createTypedArrayList(Uri.CREATOR);
|
||||
mBytes = src.createByteArray();
|
||||
|
||||
data = src.readParcelable(getClass().getClassLoader());
|
||||
}
|
||||
|
||||
public boolean isIncomplete() {
|
||||
return mInputUris.size() > mOutputUris.size();
|
||||
List<Uri> inputUris = getInputUris();
|
||||
List<Uri> outputUris = getOutputUris();
|
||||
if (inputUris == null || outputUris == null) {
|
||||
throw new IllegalStateException("Invalid operation for bytes-backed SignEncryptParcel!");
|
||||
}
|
||||
return inputUris.size() > outputUris.size();
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return mBytes;
|
||||
|
||||
public static SignEncryptParcel createSignEncryptParcel(PgpSignEncryptData signEncryptData, byte[] bytes) {
|
||||
// noinspection unchecked, it's ok for the empty list
|
||||
return new AutoValue_SignEncryptParcel(signEncryptData, Collections.EMPTY_LIST, Collections.EMPTY_LIST, bytes);
|
||||
}
|
||||
|
||||
public void setBytes(byte[] bytes) {
|
||||
mBytes = bytes;
|
||||
public static Builder builder(SignEncryptParcel signEncryptParcel) {
|
||||
return new Builder(signEncryptParcel.getSignEncryptData())
|
||||
.addInputUris(signEncryptParcel.getInputUris())
|
||||
.addOutputUris(signEncryptParcel.getOutputUris());
|
||||
}
|
||||
|
||||
public List<Uri> getInputUris() {
|
||||
return Collections.unmodifiableList(mInputUris);
|
||||
public static Builder builder(PgpSignEncryptData signEncryptData) {
|
||||
return new Builder(signEncryptData);
|
||||
}
|
||||
|
||||
public void addInputUris(Collection<Uri> inputUris) {
|
||||
mInputUris.addAll(inputUris);
|
||||
}
|
||||
|
||||
public List<Uri> getOutputUris() {
|
||||
return Collections.unmodifiableList(mOutputUris);
|
||||
}
|
||||
public static class Builder {
|
||||
private final PgpSignEncryptData signEncryptData;
|
||||
private ArrayList<Uri> inputUris = new ArrayList<>();
|
||||
private ArrayList<Uri> outputUris = new ArrayList<>();
|
||||
|
||||
public void addOutputUris(ArrayList<Uri> outputUris) {
|
||||
mOutputUris.addAll(outputUris);
|
||||
}
|
||||
|
||||
public void setData(PgpSignEncryptData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public PgpSignEncryptData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeTypedList(mInputUris);
|
||||
dest.writeTypedList(mOutputUris);
|
||||
dest.writeByteArray(mBytes);
|
||||
|
||||
dest.writeParcelable(data, 0);
|
||||
}
|
||||
|
||||
public static final Creator<SignEncryptParcel> CREATOR = new Creator<SignEncryptParcel>() {
|
||||
public SignEncryptParcel createFromParcel(final Parcel source) {
|
||||
return new SignEncryptParcel(source);
|
||||
private Builder(PgpSignEncryptData signEncryptData) {
|
||||
this.signEncryptData = signEncryptData;
|
||||
}
|
||||
|
||||
public SignEncryptParcel[] newArray(final int size) {
|
||||
return new SignEncryptParcel[size];
|
||||
public SignEncryptParcel build() {
|
||||
return new AutoValue_SignEncryptParcel(signEncryptData,
|
||||
Collections.unmodifiableList(inputUris),
|
||||
Collections.unmodifiableList(outputUris),
|
||||
null);
|
||||
}
|
||||
};
|
||||
|
||||
public Builder addOutputUris(Collection<Uri> outputUris) {
|
||||
this.outputUris.addAll(outputUris);
|
||||
return this;
|
||||
}
|
||||
public Builder addInputUris(Collection<Uri> inputUris) {
|
||||
this.inputUris.addAll(inputUris);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,65 +17,24 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||
|
||||
|
||||
public class InputDataParcel implements Parcelable {
|
||||
@AutoValue
|
||||
public abstract class InputDataParcel implements Parcelable {
|
||||
public abstract Uri getInputUri();
|
||||
@Nullable
|
||||
public abstract PgpDecryptVerifyInputParcel getDecryptInput();
|
||||
public abstract boolean getMimeDecode(); // TODO static value - ditch this?
|
||||
|
||||
private Uri mInputUri;
|
||||
|
||||
private PgpDecryptVerifyInputParcel mDecryptInput;
|
||||
private boolean mMimeDecode = true; // TODO default to false
|
||||
|
||||
public InputDataParcel(Uri inputUri, PgpDecryptVerifyInputParcel decryptInput) {
|
||||
mInputUri = inputUri;
|
||||
mDecryptInput = decryptInput;
|
||||
public static InputDataParcel createInputDataParcel(Uri inputUri, PgpDecryptVerifyInputParcel decryptInput) {
|
||||
return new AutoValue_InputDataParcel(inputUri, decryptInput, true);
|
||||
}
|
||||
|
||||
InputDataParcel(Parcel source) {
|
||||
// we do all of those here, so the PgpSignEncryptInput class doesn't have to be parcelable
|
||||
mInputUri = source.readParcelable(getClass().getClassLoader());
|
||||
mDecryptInput = source.readParcelable(getClass().getClassLoader());
|
||||
mMimeDecode = source.readInt() != 0;
|
||||
}
|
||||
|
||||
public Uri getInputUri() {
|
||||
return mInputUri;
|
||||
}
|
||||
|
||||
public PgpDecryptVerifyInputParcel getDecryptInput() {
|
||||
return mDecryptInput;
|
||||
}
|
||||
|
||||
public boolean getMimeDecode() {
|
||||
return mMimeDecode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(mInputUri, 0);
|
||||
dest.writeParcelable(mDecryptInput, 0);
|
||||
dest.writeInt(mMimeDecode ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Creator<InputDataParcel> CREATOR = new Creator<InputDataParcel>() {
|
||||
public InputDataParcel createFromParcel(final Parcel source) {
|
||||
return new InputDataParcel(source);
|
||||
}
|
||||
|
||||
public InputDataParcel[] newArray(final int size) {
|
||||
return new InputDataParcel[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ public class DecryptListFragment
|
|||
|
||||
PgpDecryptVerifyInputParcel decryptInput = new PgpDecryptVerifyInputParcel()
|
||||
.setAllowSymmetricDecryption(true);
|
||||
return new InputDataParcel(mCurrentInputUri, decryptInput);
|
||||
return InputDataParcel.createInputDataParcel(mCurrentInputUri, decryptInput);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -577,12 +577,10 @@ public class EncryptFilesFragment
|
|||
}
|
||||
|
||||
public SignEncryptParcel createOperationInput() {
|
||||
|
||||
SignEncryptParcel actionsParcel = getCachedActionsParcel();
|
||||
|
||||
// we have three cases here: nothing cached, cached except output, fully cached
|
||||
if (actionsParcel == null) {
|
||||
|
||||
// clear output uris for now, they will be created by prepareOutputStreams later
|
||||
mOutputUris = null;
|
||||
|
||||
|
@ -593,7 +591,6 @@ public class EncryptFilesFragment
|
|||
}
|
||||
|
||||
cacheActionsParcel(actionsParcel);
|
||||
|
||||
}
|
||||
|
||||
// if it's incomplete, prepare output streams
|
||||
|
@ -606,9 +603,10 @@ public class EncryptFilesFragment
|
|||
}
|
||||
}
|
||||
|
||||
actionsParcel.addOutputUris(mOutputUris);
|
||||
actionsParcel = SignEncryptParcel.builder(actionsParcel)
|
||||
.addOutputUris(mOutputUris)
|
||||
.build();
|
||||
cacheActionsParcel(actionsParcel);
|
||||
|
||||
}
|
||||
|
||||
return actionsParcel;
|
||||
|
@ -675,10 +673,9 @@ public class EncryptFilesFragment
|
|||
}
|
||||
|
||||
|
||||
SignEncryptParcel parcel = new SignEncryptParcel(data.build());
|
||||
parcel.addInputUris(mFilesAdapter.getAsArrayList());
|
||||
|
||||
return parcel;
|
||||
SignEncryptParcel.Builder builder = SignEncryptParcel.builder(data.build());
|
||||
builder.addInputUris(mFilesAdapter.getAsArrayList());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private Intent createSendIntent() {
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
|
@ -49,10 +54,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
|||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EncryptTextFragment
|
||||
extends CachingCryptoOperationFragment<SignEncryptParcel, SignEncryptResult> {
|
||||
|
||||
|
@ -286,10 +287,7 @@ public class EncryptTextFragment
|
|||
data.setSymmetricPassphrase(passphrase);
|
||||
}
|
||||
|
||||
SignEncryptParcel parcel = new SignEncryptParcel(data.build());
|
||||
parcel.setBytes(mMessage.getBytes());
|
||||
|
||||
return parcel;
|
||||
return SignEncryptParcel.createSignEncryptParcel(data.build(), mMessage.getBytes());
|
||||
}
|
||||
|
||||
private void copyToClipboard(SignEncryptResult result) {
|
||||
|
|
|
@ -128,7 +128,7 @@ public class InputDataOperationTest {
|
|||
InputDataOperation op = new InputDataOperation(spyApplication,
|
||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||
|
||||
InputDataParcel input = new InputDataParcel(fakeInputUri, null);
|
||||
InputDataParcel input = InputDataParcel.createInputDataParcel(fakeInputUri, null);
|
||||
|
||||
InputDataResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||
|
||||
|
@ -308,7 +308,7 @@ public class InputDataOperationTest {
|
|||
InputDataOperation op = new InputDataOperation(spyApplication,
|
||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||
|
||||
InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
|
||||
InputDataParcel input = InputDataParcel.createInputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
|
||||
return op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue