diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-16 19:54:57 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-16 19:54:57 +0200 |
commit | 6624d1f8304a07ac43e7f22a138262bba9782758 (patch) | |
tree | 6e37299002a48c0264cfd6b19a19249b2790dfd8 | |
parent | ece06b1933c26688d2eb6b7fa8657acbb8833728 (diff) | |
download | open-keychain-6624d1f8304a07ac43e7f22a138262bba9782758.tar.gz open-keychain-6624d1f8304a07ac43e7f22a138262bba9782758.tar.bz2 open-keychain-6624d1f8304a07ac43e7f22a138262bba9782758.zip |
mime: respect charset header (default to utf-8)
7 files changed, 21 insertions, 25 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index a5208e05b..5e932ffc9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -172,7 +172,13 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> { log.add(LogType.MSG_DATA_MIME_LENGTH, 3, totalLength); - OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, totalLength); + String charset = bd.getCharset(); + // the charset defaults to us-ascii, but we want to default to utf-8 + if ("us-ascii".equals(charset)) { + charset = "utf-8"; + } + + OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, totalLength, charset); out.close(); outputUris.add(uri); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java index e8be9fa78..95cf179af 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java @@ -34,9 +34,6 @@ public class DecryptVerifyResult extends InputPendingResult { OpenPgpSignatureResult mSignatureResult; OpenPgpDecryptionResult mDecryptionResult; OpenPgpMetadata mDecryptionMetadata; - // This holds the charset which was specified in the ascii armor, if specified - // https://tools.ietf.org/html/rfc4880#page56 - String mCharset; CryptoInputParcel mCachedCryptoInputParcel; @@ -96,14 +93,6 @@ public class DecryptVerifyResult extends InputPendingResult { mDecryptionMetadata = decryptMetadata; } - public String getCharset () { - return mCharset; - } - - public void setCharset(String charset) { - mCharset = charset; - } - public void setOutputBytes(byte[] outputBytes) { mOutputBytes = outputBytes; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index dda15f382..007f686e8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -556,12 +556,12 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp originalFilename, mimeType, literalData.getModificationTime().getTime(), - originalSize == null ? 0 : originalSize); + originalSize == null ? 0 : originalSize, + charset); log.add(LogType.MSG_DC_OK_META_ONLY, indent); DecryptVerifyResult result = new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log); - result.setCharset(charset); result.setDecryptionMetadata(metadata); return result; } @@ -607,7 +607,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp } metadata = new OpenPgpMetadata( - originalFilename, mimeType, literalData.getModificationTime().getTime(), alreadyWritten); + originalFilename, mimeType, literalData.getModificationTime().getTime(), alreadyWritten, charset); if (signature != null) { updateProgress(R.string.progress_verifying_signature, 90, 100); @@ -663,7 +663,6 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp result.setCachedCryptoInputParcel(cryptoInput); result.setSignatureResult(signatureResultBuilder.build()); - result.setCharset(charset); result.setDecryptionResult(decryptionResultBuilder.build()); result.setDecryptionMetadata(metadata); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 57dd068ef..e7709e58e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -628,15 +628,14 @@ public class OpenPgpService extends RemoteService { } } - + OpenPgpMetadata metadata = pgpResult.getDecryptionMetadata(); if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) >= 4) { - OpenPgpMetadata metadata = pgpResult.getDecryptionMetadata(); if (metadata != null) { result.putExtra(OpenPgpApi.RESULT_METADATA, metadata); } } - String charset = pgpResult.getCharset(); + String charset = metadata != null ? metadata.getCharset() : null; if (charset != null) { result.putExtra(OpenPgpApi.RESULT_CHARSET, charset); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index 98d8c1ba8..af1108488 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -472,7 +472,8 @@ public class DecryptListFragment Intent intent = new Intent(activity, DisplayTextActivity.class); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(outputUri, "text/plain"); - intent.putExtra(DisplayTextActivity.EXTRA_METADATA, result.mDecryptVerifyResult); + intent.putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult); + intent.putExtra(DisplayTextActivity.EXTRA_METADATA, metadata); activity.startActivity(intent); } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java index 3c8e972b9..4bcca09f1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java @@ -25,9 +25,9 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.view.View; import android.widget.Toast; +import org.openintents.openpgp.OpenPgpMetadata; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -35,6 +35,7 @@ import org.sufficientlysecure.keychain.util.FileHelper; public class DisplayTextActivity extends BaseActivity { + public static final String EXTRA_RESULT = "result"; public static final String EXTRA_METADATA = "metadata"; @Override @@ -60,11 +61,12 @@ public class DisplayTextActivity extends BaseActivity { return; } - DecryptVerifyResult result = intent.getParcelableExtra(EXTRA_METADATA); + DecryptVerifyResult result = intent.getParcelableExtra(EXTRA_RESULT); + OpenPgpMetadata metadata = intent.getParcelableExtra(EXTRA_METADATA); String plaintext; try { - plaintext = FileHelper.readTextFromUri(this, intent.getData(), result.getCharset()); + plaintext = FileHelper.readTextFromUri(this, intent.getData(), metadata.getCharset()); } catch (IOException e) { Toast.makeText(this, R.string.error_preparing_data, Toast.LENGTH_LONG).show(); return; diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 727464429..cc5ef8038 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -792,9 +792,9 @@ public class PgpEncryptDecryptTest { Assert.assertArrayEquals("decrypted ciphertext should equal plaintext bytes", out.toByteArray(), plaindata); Assert.assertEquals("charset should be read correctly", - "iso-2022-jp", result.getCharset()); + "iso-2022-jp", result.getDecryptionMetadata().getCharset()); Assert.assertEquals("decrypted ciphertext should equal plaintext", - new String(out.toByteArray(), result.getCharset()), plaintext); + new String(out.toByteArray(), result.getDecryptionMetadata().getCharset()), plaintext); Assert.assertEquals("decryptionResult should be RESULT_ENCRYPTED", OpenPgpDecryptionResult.RESULT_ENCRYPTED, result.getDecryptionResult().getResult()); Assert.assertEquals("signatureResult should be RESULT_NO_SIGNATURE", |