fix tests for new PgpSignEncryptInput

This commit is contained in:
Vincent Breitmoser 2015-02-02 12:29:37 +01:00
parent 7b24ee7b55
commit d125149bf7

View File

@ -130,15 +130,17 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
InputData data = new InputData(in, in.available()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application,
Builder b = new PgpSignEncryptOperation.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), null);
new ProviderHelper(Robolectric.application),
null,
data, out);
InputData data = new InputData(in, in.available());
PgpSignEncryptInput b = new PgpSignEncryptInput();
b.setSymmetricPassphrase(mPassphrase); b.setSymmetricPassphrase(mPassphrase);
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
PgpSignEncryptResult result = b.build().execute();
PgpSignEncryptResult result = op.execute(b, data, out);
Assert.assertTrue("encryption must succeed", result.success()); Assert.assertTrue("encryption must succeed", result.success());
ciphertext = out.toByteArray(); ciphertext = out.toByteArray();
@ -209,16 +211,15 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application,
new ProviderHelper(Robolectric.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
Builder b = new PgpSignEncryptOperation.Builder( PgpSignEncryptInput b = new PgpSignEncryptInput();
Robolectric.application,
new ProviderHelper(Robolectric.application),
null, // new DummyPassphraseCache(mPassphrase, 0L),
data, out);
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
PgpSignEncryptResult result = b.build().execute(); PgpSignEncryptResult result = op.execute(b, data, out);
Assert.assertTrue("encryption must succeed", result.success()); Assert.assertTrue("encryption must succeed", result.success());
ciphertext = out.toByteArray(); ciphertext = out.toByteArray();
@ -285,19 +286,19 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
InputData data = new InputData(in, in.available()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application,
Builder b = new PgpSignEncryptOperation.Builder( new ProviderHelper(Robolectric.application), null);
Robolectric.application,
new ProviderHelper(Robolectric.application),
null, // new DummyPassphraseCache(mPassphrase, 0L),
data, out);
InputData data = new InputData(in, in.available());
PgpSignEncryptInput b = new PgpSignEncryptInput();
b.setEncryptionMasterKeyIds(new long[] { b.setEncryptionMasterKeyIds(new long[] {
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(),
mStaticRing2.getMasterKeyId() mStaticRing2.getMasterKeyId()
}); });
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
PgpSignEncryptResult result = b.build().execute();
PgpSignEncryptResult result = op.execute(b, data, out);
Assert.assertTrue("encryption must succeed", result.success()); Assert.assertTrue("encryption must succeed", result.success());
ciphertext = out.toByteArray(); ciphertext = out.toByteArray();
@ -374,12 +375,11 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application,
new ProviderHelper(Robolectric.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
Builder b = new PgpSignEncryptOperation.Builder( PgpSignEncryptInput b = new PgpSignEncryptInput();
Robolectric.application,
new ProviderHelper(Robolectric.application),
null, // new DummyPassphraseCache(mPassphrase, 0L),
data, out);
b.setEncryptionMasterKeyIds(new long[] { b.setEncryptionMasterKeyIds(new long[] {
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(),
@ -389,7 +389,8 @@ public class PgpEncryptDecryptTest {
b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1)); b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1));
b.setSignaturePassphrase(mKeyPhrase1); b.setSignaturePassphrase(mKeyPhrase1);
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
PgpSignEncryptResult result = b.build().execute();
PgpSignEncryptResult result = op.execute(b, data, out);
Assert.assertTrue("encryption must succeed", result.success()); Assert.assertTrue("encryption must succeed", result.success());
ciphertext = out.toByteArray(); ciphertext = out.toByteArray();
@ -452,19 +453,18 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaindata); ByteArrayInputStream in = new ByteArrayInputStream(plaindata);
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application,
new ProviderHelper(Robolectric.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
Builder b = new PgpSignEncryptOperation.Builder( PgpSignEncryptInput b = new PgpSignEncryptInput();
Robolectric.application,
new ProviderHelper(Robolectric.application),
null, // new DummyPassphraseCache(mPassphrase, 0L),
data, out);
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
// this only works with ascii armored output! // this only works with ascii armored output!
b.setEnableAsciiArmorOutput(true); b.setEnableAsciiArmorOutput(true);
b.setCharset("iso-2022-jp"); b.setCharset("iso-2022-jp");
PgpSignEncryptResult result = b.build().execute(); PgpSignEncryptResult result = op.execute(b, data, out);
Assert.assertTrue("encryption must succeed", result.success()); Assert.assertTrue("encryption must succeed", result.success());
ciphertext = out.toByteArray(); ciphertext = out.toByteArray();