use autovalue for CertifyActionsParcel

This commit is contained in:
Vincent Breitmoser
2017-05-22 11:25:52 +02:00
parent 63774a0632
commit 53dcb4102d
9 changed files with 125 additions and 130 deletions

View File

@@ -153,10 +153,10 @@ public class CertifyOperationTest {
Certs.UNVERIFIED, ring.getVerified());
}
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());
actions.addAction(CertifyAction.createForUserIds(mStaticRing2.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds()));
CertifyResult result = op.execute(actions.build(), CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
Assert.assertTrue("certification must succeed", result.success());
@@ -181,10 +181,10 @@ public class CertifyOperationTest {
Certs.UNVERIFIED, ring.getVerified());
}
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());
actions.addAction(CertifyAction.createForUserAttributes(mStaticRing2.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
CertifyResult result = op.execute(actions.build(), CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
Assert.assertTrue("certification must succeed", result.success());
@@ -203,11 +203,11 @@ public class CertifyOperationTest {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());
actions.addAction(CertifyAction.createForUserIds(mStaticRing1.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds()));
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
CertifyResult result = op.execute(actions.build(), CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
Assert.assertFalse("certification with itself must fail!", result.success());
Assert.assertTrue("error msg must be about self certification",
@@ -221,12 +221,12 @@ public class CertifyOperationTest {
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
{
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(mStaticRing1.getMasterKeyId());
ArrayList<String> uids = new ArrayList<String>();
uids.add("nonexistent");
actions.add(new CertifyAction(1234L, uids, null));
actions.addAction(CertifyAction.createForUserIds(1234L, uids));
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(),
CertifyResult result = op.execute(actions.build(), CryptoInputParcel.createCryptoInputParcel(new Date(),
mKeyPhrase1));
Assert.assertFalse("certification of nonexistent key must fail", result.success());
@@ -235,11 +235,11 @@ public class CertifyOperationTest {
}
{
CertifyActionsParcel actions = new CertifyActionsParcel(1234L);
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
CertifyActionsParcel.Builder actions = CertifyActionsParcel.builder(1234L);
actions.addAction(CertifyAction.createForUserIds(mStaticRing1.getMasterKeyId(),
mStaticRing2.getPublicKey().getUnorderedUserIds()));
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(),
CertifyResult result = op.execute(actions.build(), CryptoInputParcel.createCryptoInputParcel(new Date(),
mKeyPhrase1));
Assert.assertFalse("certification of nonexistent key must fail", result.success());

View File

@@ -18,6 +18,14 @@
package org.sufficientlysecure.keychain.pgp;
import java.io.ByteArrayInputStream;
import java.security.Security;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Random;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.PacketTags;
import org.bouncycastle.bcpg.S2K;
@@ -304,7 +312,8 @@ public class UncachedKeyringMergeTest {
ringB.getEncoded(), 0).getSecretKey();
secretKey.unlock(new Passphrase());
PgpCertifyOperation op = new PgpCertifyOperation();
CertifyAction action = new CertifyAction(pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds(), null);
CertifyAction action = CertifyAction.createForUserIds(
pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds());
// sign all user ids
PgpCertifyResult result = op.certify(secretKey, publicRing, new OperationLog(), 0, action, null, new Date());
Assert.assertTrue("certification must succeed", result.success());

View File

@@ -194,11 +194,12 @@ public class KeychainExternalProviderTest {
}
private void certifyKey(long secretMasterKeyId, long publicMasterKeyId, String userId) {
CertifyActionsParcel certifyActionsParcel = new CertifyActionsParcel(secretMasterKeyId);
certifyActionsParcel.add(new CertifyAction(publicMasterKeyId, Collections.singletonList(userId), null));
CertifyActionsParcel.Builder certifyActionsParcel = CertifyActionsParcel.builder(secretMasterKeyId);
certifyActionsParcel.addAction(
CertifyAction.createForUserIds(publicMasterKeyId, Collections.singletonList(userId)));
CertifyOperation op = new CertifyOperation(
RuntimeEnvironment.application, databaseInteractor, new ProgressScaler(), null);
CertifyResult certifyResult = op.execute(certifyActionsParcel, CryptoInputParcel.createCryptoInputParcel());
CertifyResult certifyResult = op.execute(certifyActionsParcel.build(), CryptoInputParcel.createCryptoInputParcel());
assertTrue(certifyResult.success());
}