use autovalue for UploadKeyringParcel
This commit is contained in:
@@ -144,7 +144,7 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
UploadKeyringParcel exportKeyringParcel =
|
UploadKeyringParcel exportKeyringParcel =
|
||||||
new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes);
|
UploadKeyringParcel.createWithKeyringBytes(saveParcel.getUploadKeyserver(), keyringBytes);
|
||||||
|
|
||||||
UploadResult uploadResult = new UploadOperation(
|
UploadResult uploadResult = new UploadOperation(
|
||||||
mContext, mKeyRepository, new ProgressScaler(mProgressable, 60, 80, 100), mCancelled)
|
mContext, mKeyRepository, new ProgressScaler(mProgressable, 60, 80, 100), mCancelled)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
|||||||
|
|
||||||
ParcelableHkpKeyserver hkpKeyserver;
|
ParcelableHkpKeyserver hkpKeyserver;
|
||||||
{
|
{
|
||||||
hkpKeyserver = uploadInput.mKeyserver;
|
hkpKeyserver = uploadInput.getKeyserver();
|
||||||
log.add(LogType.MSG_UPLOAD_SERVER, 1, hkpKeyserver.toString());
|
log.add(LogType.MSG_UPLOAD_SERVER, 1, hkpKeyserver.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,22 +110,15 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CanonicalizedPublicKeyRing getPublicKeyringFromInput(OperationLog log, UploadKeyringParcel uploadInput) {
|
private CanonicalizedPublicKeyRing getPublicKeyringFromInput(OperationLog log, UploadKeyringParcel uploadInput) {
|
||||||
|
|
||||||
boolean hasMasterKeyId = uploadInput.mMasterKeyId != null;
|
|
||||||
boolean hasKeyringBytes = uploadInput.mUncachedKeyringBytes != null;
|
|
||||||
if (hasMasterKeyId == hasKeyringBytes) {
|
|
||||||
throw new IllegalArgumentException("either keyid xor bytes must be non-null for this method call!");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Long masterKeyId = uploadInput.getMasterKeyId();
|
||||||
if (hasMasterKeyId) {
|
if (masterKeyId != null) {
|
||||||
log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId));
|
log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(masterKeyId));
|
||||||
return mKeyRepository.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId);
|
return mKeyRepository.getCanonicalizedPublicKeyRing(masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
CanonicalizedKeyRing canonicalizedRing =
|
CanonicalizedKeyRing canonicalizedRing =
|
||||||
UncachedKeyRing.decodeFromData(uploadInput.mUncachedKeyringBytes)
|
UncachedKeyRing.decodeFromData(uploadInput.getUncachedKeyringBytes())
|
||||||
.canonicalize(new OperationLog(), 0, true);
|
.canonicalize(new OperationLog(), 0, true);
|
||||||
if (!CanonicalizedPublicKeyRing.class.isInstance(canonicalizedRing)) {
|
if (!CanonicalizedPublicKeyRing.class.isInstance(canonicalizedRing)) {
|
||||||
throw new IllegalArgumentException("keyring bytes must contain public key ring!");
|
throw new IllegalArgumentException("keyring bytes must contain public key ring!");
|
||||||
|
|||||||
@@ -20,62 +20,28 @@
|
|||||||
package org.sufficientlysecure.keychain.service;
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class UploadKeyringParcel implements Parcelable {
|
||||||
|
public abstract ParcelableHkpKeyserver getKeyserver();
|
||||||
|
@Nullable
|
||||||
|
public abstract Long getMasterKeyId();
|
||||||
|
@Nullable
|
||||||
|
public abstract byte[] getUncachedKeyringBytes();
|
||||||
|
|
||||||
public class UploadKeyringParcel implements Parcelable {
|
|
||||||
public ParcelableHkpKeyserver mKeyserver;
|
|
||||||
|
|
||||||
public final Long mMasterKeyId;
|
public static UploadKeyringParcel createWithKeyId(ParcelableHkpKeyserver keyserver, long masterKeyId) {
|
||||||
public final byte[] mUncachedKeyringBytes;
|
return new AutoValue_UploadKeyringParcel(keyserver, masterKeyId, null);
|
||||||
|
|
||||||
public UploadKeyringParcel(ParcelableHkpKeyserver keyserver, long masterKeyId) {
|
|
||||||
mKeyserver = keyserver;
|
|
||||||
mMasterKeyId = masterKeyId;
|
|
||||||
mUncachedKeyringBytes = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadKeyringParcel(ParcelableHkpKeyserver keyserver, byte[] uncachedKeyringBytes) {
|
public static UploadKeyringParcel createWithKeyringBytes(ParcelableHkpKeyserver keyserver,
|
||||||
mKeyserver = keyserver;
|
@NonNull byte[] uncachedKeyringBytes) {
|
||||||
mMasterKeyId = null;
|
return new AutoValue_UploadKeyringParcel(keyserver, null, uncachedKeyringBytes);
|
||||||
mUncachedKeyringBytes = uncachedKeyringBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UploadKeyringParcel(Parcel in) {
|
|
||||||
mKeyserver = in.readParcelable(ParcelableHkpKeyserver.class.getClassLoader());
|
|
||||||
mMasterKeyId = in.readInt() != 0 ? in.readLong() : null;
|
|
||||||
mUncachedKeyringBytes = in.createByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeParcelable(mKeyserver, flags);
|
|
||||||
if (mMasterKeyId != null) {
|
|
||||||
dest.writeInt(1);
|
|
||||||
dest.writeLong(mMasterKeyId);
|
|
||||||
} else {
|
|
||||||
dest.writeInt(0);
|
|
||||||
}
|
|
||||||
dest.writeByteArray(mUncachedKeyringBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<UploadKeyringParcel> CREATOR = new Creator<UploadKeyringParcel>() {
|
|
||||||
@Override
|
|
||||||
public UploadKeyringParcel createFromParcel(Parcel in) {
|
|
||||||
return new UploadKeyringParcel(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UploadKeyringParcel[] newArray(int size) {
|
|
||||||
return new UploadKeyringParcel[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadKeyringParcel createOperationInput() {
|
public UploadKeyringParcel createOperationInput() {
|
||||||
return new UploadKeyringParcel(keyserver, masterKeyId);
|
return UploadKeyringParcel.createWithKeyId(keyserver, masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ public class EditIdentitiesFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadKeyringParcel createOperationInput() {
|
public UploadKeyringParcel createOperationInput() {
|
||||||
return new UploadKeyringParcel(keyserver, masterKeyId);
|
return UploadKeyringParcel.createWithKeyId(keyserver, masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public class UploadKeyActivity extends BaseActivity
|
|||||||
public UploadKeyringParcel createOperationInput() {
|
public UploadKeyringParcel createOperationInput() {
|
||||||
long[] masterKeyIds = getIntent().getLongArrayExtra(MultiUserIdsFragment.EXTRA_KEY_IDS);
|
long[] masterKeyIds = getIntent().getLongArrayExtra(MultiUserIdsFragment.EXTRA_KEY_IDS);
|
||||||
|
|
||||||
return new UploadKeyringParcel(mKeyserver, masterKeyIds[0]);
|
return UploadKeyringParcel.createWithKeyId(mKeyserver, masterKeyIds[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user