summaryrefslogtreecommitdiff
path: root/alot/crypto.py
diff options
context:
space:
mode:
authorMartin Schaaf <mschaaf@datameer.com>2017-10-23 22:46:37 +0200
committerMartin Schaaf <mschaaf@datameer.com>2017-11-07 19:59:21 +0100
commit9cff2f128c3e05a5d7876c010f7cb134a372815d (patch)
treef7392a8eb00b2383648af8c610135944fe19e378 /alot/crypto.py
parent969dd7b1b71b6882cecd95427b60c3f61176d578 (diff)
Don't use __str__ of error BadSignature
It seems not to be to handle error messages of different locale than en
Diffstat (limited to 'alot/crypto.py')
-rw-r--r--alot/crypto.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/alot/crypto.py b/alot/crypto.py
index 5ed3a909..4ebb72f7 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -173,6 +173,22 @@ def encrypt(plaintext_str, keys):
return out
+NO_ERROR = None
+
+
+def bad_signatures_to_str(error):
+ """
+ Convert a bad signature exception to a text message.
+ This is a workaround for gpg not handling non-ascii data correctly.
+
+ :param BadSignatures error: BadSignatures exception
+ """
+ return ", ".join("{}: {}".format(s.fpr,
+ "Bad signature for key(s)")
+ for s in error.result.signatures
+ if s.status != NO_ERROR)
+
+
def verify_detached(message, signature):
"""Verifies whether the message is authentic by checking the signature.
@@ -187,7 +203,7 @@ def verify_detached(message, signature):
verify_results = ctx.verify(message, signature)[1]
return verify_results.signatures
except gpg.errors.BadSignatures as e:
- raise GPGProblem(str(e), code=GPGCode.BAD_SIGNATURE)
+ raise GPGProblem(bad_signatures_to_str(e), code=GPGCode.BAD_SIGNATURE)
except gpg.errors.GPGMEError as e:
raise GPGProblem(str(e), code=e.getcode())