diff options
| author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-01-27 09:46:42 +0100 | 
|---|---|---|
| committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-01-27 09:46:42 +0100 | 
| commit | e8780b4410c4e4a45f08b4002722b32f0d22d279 (patch) | |
| tree | 431846d5aba6b86a7a7ed3afd99976b9201dd471 /OpenKeychain-Test/src/test/java/org/sufficientlysecure | |
| parent | fd29d27e61e531378f0c37c78028fb2e86989dea (diff) | |
| parent | e77f9a535119f25b0f3ad31ef8065db18ceddff7 (diff) | |
| download | open-keychain-e8780b4410c4e4a45f08b4002722b32f0d22d279.tar.gz open-keychain-e8780b4410c4e4a45f08b4002722b32f0d22d279.tar.bz2 open-keychain-e8780b4410c4e4a45f08b4002722b32f0d22d279.zip  | |
Merge branch 'development' into detached-sigs-api
Conflicts:
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
Diffstat (limited to 'OpenKeychain-Test/src/test/java/org/sufficientlysecure')
| -rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java | 54 | 
1 files changed, 54 insertions, 0 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 008edcda4..b8205a792 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -438,6 +438,60 @@ public class PgpEncryptDecryptTest {      } +    @Test +    public void testForeignEncoding () throws Exception { +        String plaintext = "ウィキペディア"; +        byte[] plaindata = plaintext.getBytes("iso-2022-jp"); + +        { // some quick sanity checks +            Assert.assertEquals(plaintext, new String(plaindata, "iso-2022-jp")); +            Assert.assertNotEquals(plaintext, new String(plaindata, "utf-8")); +        } + +        byte[] ciphertext; +        { // encrypt data with a given passphrase +            ByteArrayOutputStream out = new ByteArrayOutputStream(); +            ByteArrayInputStream in = new ByteArrayInputStream(plaindata); + +            InputData data = new InputData(in, in.available()); +            Builder b = new PgpSignEncrypt.Builder( +                    Robolectric.application, +                    new ProviderHelper(Robolectric.application), +                    null, // new DummyPassphraseCache(mPassphrase, 0L), +                    data, out); + +            b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); +            b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); +            // this only works with ascii armored output! +            b.setEnableAsciiArmorOutput(true); +            b.setCharset("iso-2022-jp"); +            SignEncryptResult result = b.build().execute(); +            Assert.assertTrue("encryption must succeed", result.success()); + +            ciphertext = out.toByteArray(); +        } + +        { // decryption with provided passphrase should yield the same result + +            ByteArrayOutputStream out = new ByteArrayOutputStream(); +            ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); +            InputData data = new InputData(in, in.available()); + +            PgpDecryptVerify.Builder b = builderWithFakePassphraseCache(data, out, null, null, null); +            b.setPassphrase(mKeyPhrase1); +            DecryptVerifyResult result = b.build().execute(); +            Assert.assertTrue("decryption with provided passphrase must succeed", result.success()); +            Assert.assertArrayEquals("decrypted ciphertext should equal plaintext bytes", +                    out.toByteArray(), plaindata); +            Assert.assertEquals("charset should be read correctly", +                    "iso-2022-jp", result.getCharset()); +            Assert.assertEquals("decrypted ciphertext should equal plaintext", +                    new String(out.toByteArray(), result.getCharset()), plaintext); +            Assert.assertNull("signature be empty", result.getSignatureResult()); +        } + +    } +      private PgpDecryptVerify.Builder builderWithFakePassphraseCache (              InputData data, OutputStream out,              final String passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {  | 
