diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-08-13 11:21:07 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-08-13 11:21:07 +0200 |
commit | 07e6873025a29df6ab3d9597c9f0457616add55a (patch) | |
tree | 0f0777248b82369caf4ffd790d0295376fe30c77 /src/eu/siacs/conversations/crypto/PgpEngine.java | |
parent | 5477ff1aeaf68fdb2ff68f35c5d72171074293a0 (diff) |
try to make openpgp a little more reliable
Diffstat (limited to 'src/eu/siacs/conversations/crypto/PgpEngine.java')
-rw-r--r-- | src/eu/siacs/conversations/crypto/PgpEngine.java | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 2d0c56e1..65b7ccc7 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -54,9 +54,18 @@ public class PgpEngine { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: - message.setBody(os.toString()); - message.setEncryption(Message.ENCRYPTION_DECRYPTED); - callback.success(message); + try { + os.flush(); + if (message.getEncryption() == Message.ENCRYPTION_PGP) { + message.setBody(os.toString()); + message.setEncryption(Message.ENCRYPTION_DECRYPTED); + callback.success(message); + } + } catch (IOException e) { + callback.error(R.string.openpgp_error, message); + return; + } + return; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: callback.userInputRequried((PendingIntent) result @@ -64,6 +73,8 @@ public class PgpEngine { message); return; case OpenPgpApi.RESULT_CODE_ERROR: + OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + Log.d("xmppService",error.getMessage()); callback.error(R.string.openpgp_error, message); return; default: @@ -153,14 +164,20 @@ public class PgpEngine { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: - StringBuilder encryptedMessageBody = new StringBuilder(); - String[] lines = os.toString().split("\n"); - for (int i = 3; i < lines.length - 1; ++i) { - encryptedMessageBody.append(lines[i].trim()); + try { + os.flush(); + StringBuilder encryptedMessageBody = new StringBuilder(); + String[] lines = os.toString().split("\n"); + for (int i = 3; i < lines.length - 1; ++i) { + encryptedMessageBody.append(lines[i].trim()); + } + message.setEncryptedBody(encryptedMessageBody + .toString()); + callback.success(message); + } catch (IOException e) { + callback.error(R.string.openpgp_error, message); } - message.setEncryptedBody(encryptedMessageBody - .toString()); - callback.success(message); + break; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: callback.userInputRequried((PendingIntent) result |