From acd71a45c09ad6668a03ec74399d8f526ab647e2 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Thu, 15 Apr 2010 14:37:46 +0000 Subject: [PATCH] minor layout fixes, replace non breakable spaces if found in an encrypted armored message, as they break the decryption, the HTML representation of GMail introduces them for empty lines ending in a normal space, also adjusted the PGP_MESSAGE regex to allow for spaces after the -----, which seems to be added by some implementations --- res/layout/mailbox_message_item.xml | 2 +- src/org/thialfihar/android/apg/Apg.java | 16 +++++++++++----- .../android/apg/DecryptMessageActivity.java | 7 +++++-- .../android/apg/EncryptMessageActivity.java | 3 ++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/res/layout/mailbox_message_item.xml b/res/layout/mailbox_message_item.xml index b2b5e91d4..a5858fba3 100644 --- a/res/layout/mailbox_message_item.xml +++ b/res/layout/mailbox_message_item.xml @@ -29,7 +29,7 @@ android:src="@drawable/encrypted" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true"/> + android:layout_gravity="center_vertical"/> mSecretKeyRings; public static Pattern PGP_MESSAGE = - Pattern.compile(".*?(-----BEGIN PGP MESSAGE-----\n.*?-----END PGP MESSAGE-----).*", + Pattern.compile(".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); protected static boolean mInitialized = false; @@ -1135,6 +1135,7 @@ public class Apg { } public static void encrypt(InputStream inStream, OutputStream outStream, + boolean armored, long encryptionKeyIds[], long signatureKeyId, String signaturePassPhrase, ProgressDialogUpdater progress) @@ -1142,11 +1143,16 @@ public class Apg { NoSuchAlgorithmException, SignatureException { Security.addProvider(new BouncyCastleProvider()); - ArmoredOutputStream armorOut = new ArmoredOutputStream(outStream); - armorOut.setHeader("Version", FULL_VERSION); - OutputStream out = armorOut; + ArmoredOutputStream armorOut = null; + OutputStream out = null; OutputStream encryptOut = null; - + if (armored) { + armorOut = new ArmoredOutputStream(outStream); + armorOut.setHeader("Version", FULL_VERSION); + out = armorOut; + } else { + out = outStream; + } PGPSecretKey signingKey = null; PGPSecretKeyRing signingKeyRing = null; PGPPrivateKey signaturePrivateKey = null; diff --git a/src/org/thialfihar/android/apg/DecryptMessageActivity.java b/src/org/thialfihar/android/apg/DecryptMessageActivity.java index 179d5be55..055c8256c 100644 --- a/src/org/thialfihar/android/apg/DecryptMessageActivity.java +++ b/src/org/thialfihar/android/apg/DecryptMessageActivity.java @@ -190,6 +190,8 @@ public class DecryptMessageActivity extends Activity Matcher matcher = Apg.PGP_MESSAGE.matcher(data); if (matcher.matches()) { data = matcher.group(1); + // replace non breakable spaces + data = data.replaceAll("\\xa0", " "); mMessage.setText(data); } } @@ -312,8 +314,9 @@ public class DecryptMessageActivity extends Activity Bundle data = new Bundle(); Message msg = new Message(); - ByteArrayInputStream in = - new ByteArrayInputStream(mMessage.getText().toString().getBytes()); + String messageData = mMessage.getText().toString(); + + ByteArrayInputStream in = new ByteArrayInputStream(messageData.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { diff --git a/src/org/thialfihar/android/apg/EncryptMessageActivity.java b/src/org/thialfihar/android/apg/EncryptMessageActivity.java index 27e4c29be..af2eac82d 100644 --- a/src/org/thialfihar/android/apg/EncryptMessageActivity.java +++ b/src/org/thialfihar/android/apg/EncryptMessageActivity.java @@ -312,7 +312,8 @@ public class EncryptMessageActivity extends Activity try { if (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) { - Apg.encrypt(in, out, mEncryptionKeyIds, mSignatureKeyId, Apg.getPassPhrase(), this); + Apg.encrypt(in, out, true, mEncryptionKeyIds, mSignatureKeyId, + Apg.getPassPhrase(), this); data.putString("message", new String(out.toByteArray())); } else { Apg.sign(in, out, mSignatureKeyId, Apg.getPassPhrase(), this);