Refactored to reduce coupling between ChangeUnlockParcel and SaveKeyringParcel

This commit is contained in:
Alex Fong
2016-04-19 09:00:15 +08:00
parent a5a2335673
commit bc3aa44b22
12 changed files with 38 additions and 28 deletions

View File

@@ -33,6 +33,10 @@ public class ChangeUnlockParcel implements Parcelable {
// The new passphrase to use
public final Passphrase mNewPassphrase;
public ChangeUnlockParcel(Passphrase newPassphrase) {
mNewPassphrase = newPassphrase;
}
public ChangeUnlockParcel(Long masterKeyId, byte[] fingerprint, Passphrase newPassphrase) {
if (newPassphrase == null) {
throw new AssertionError("newPassphrase must be non-null. THIS IS A BUG!");

View File

@@ -103,11 +103,15 @@ public class SaveKeyringParcel implements Parcelable {
mKeyserver = keysever;
}
public void setNewUnlock(Passphrase passphrase) {
mNewUnlock = new ChangeUnlockParcel(mMasterKeyId, mFingerprint, passphrase);
public void setNewUnlock(ChangeUnlockParcel parcel) {
mNewUnlock = parcel;
}
public ChangeUnlockParcel getChangeUnlockParcel() {
if(mNewUnlock != null) {
mNewUnlock.mMasterKeyId = mMasterKeyId;
mNewUnlock.mFingerprint = mFingerprint;
}
return mNewUnlock;
}

View File

@@ -44,6 +44,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
@@ -288,7 +289,7 @@ public class CreateKeyFinalFragment extends Fragment {
2048, null, KeyFlags.AUTHENTICATION, 0L));
// use empty passphrase
saveKeyringParcel.setNewUnlock(new Passphrase());
saveKeyringParcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
} else {
saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA,
3072, null, KeyFlags.CERTIFY_OTHER, 0L));
@@ -298,7 +299,7 @@ public class CreateKeyFinalFragment extends Fragment {
3072, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L));
if(createKeyActivity.mPassphrase != null) {
saveKeyringParcel.setNewUnlock(createKeyActivity.mPassphrase);
saveKeyringParcel.setNewUnlock(new ChangeUnlockParcel(createKeyActivity.mPassphrase));
}
}
String userId = KeyRing.createUserId(

View File

@@ -50,6 +50,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -338,8 +339,8 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring
Bundle data = message.getData();
// cache new returned passphrase!
mSaveKeyringParcel.setNewUnlock(
(Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE));
mSaveKeyringParcel.setNewUnlock(new ChangeUnlockParcel(
(Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE)));
}
}
};