diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-11-07 20:40:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-07 20:40:48 +0000 |
commit | defaf93b51150477c11356b49803b8b01ec9e3ce (patch) | |
tree | f7392a8eb00b2383648af8c610135944fe19e378 | |
parent | 969dd7b1b71b6882cecd95427b60c3f61176d578 (diff) | |
parent | 9cff2f128c3e05a5d7876c010f7cb134a372815d (diff) |
Merge pull request #1171 from Dica-Developer/patch-3
Don't use __str__ of error BadSignature
-rw-r--r-- | alot/crypto.py | 18 |
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()) |