diff options
author | Johannes Kulick <kulick@hildensia.de> | 2012-12-19 11:54:56 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-02-19 10:10:08 +0000 |
commit | 9b8b8f5a68270912ac0dc8f16d320729b25d2da8 (patch) | |
tree | 89389307a1afa881c782e5202181c700e1a78fcf /alot/crypto.py | |
parent | 591bd897f5473d7ad97f7b2ad37df1aac50386c9 (diff) |
add error codes
to avoid import ui stuff to crypto.py I added error codes to the GPGProblem
Exceptions. This way I can process them later, depending on the error code
Diffstat (limited to 'alot/crypto.py')
-rw-r--r-- | alot/crypto.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/alot/crypto.py b/alot/crypto.py index 97449c78..76d34e8d 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -6,7 +6,7 @@ import logging from email.generator import Generator from cStringIO import StringIO -from alot.errors import GPGProblem +from alot.errors import GPGProblem, GPGCode from email.mime.multipart import MIMEMultipart import gpgme @@ -66,7 +66,8 @@ def _hash_algo_name(hash_algo): return mapping[hash_algo] else: raise GPGProblem(("Invalid hash_algo passed to hash_algo_name." - " Please report this as a bug in alot.")) + " Please report this as a bug in alot."), + code=GPGCode.INVALID_HASH) def RFC3156_micalg_from_algo(hash_algo): @@ -121,11 +122,13 @@ def get_key(keyid): key = ctx.get_key(keyid) except gpgme.GpgmeError as e: if e.code == gpgme.ERR_AMBIGUOUS_NAME: - # Deferred import to avoid a circular import dependency - raise GPGProblem(("More than one key found matching this filter." - " Please be more specific (use a key ID like 4AC8EE1D).")) + raise GPGProblem(("More than one key found matching this filter." + + " Please be more specific (use a key ID like " + + "4AC8EE1D)."), + code=GPGCode.AMBIGUOUS_NAME) elif e.code == gpgme.ERR_INV_VALUE or e.code == gpgme.ERR_EOF: - raise GPGProblem("Can not find key for " + keyid) + raise GPGProblem("Can not find key for \'" + keyid + "\'.", + code=GPGCode.NOT_FOUND) else: raise e return key @@ -202,12 +205,17 @@ def hash_key(key): def validate_key(key, sign=False, encrypt=False): if key.revoked: - raise GPGProblem("The key \"" + key.uids[0].uid + "\" is revoked.") + raise GPGProblem("The key \"" + key.uids[0].uid + "\" is revoked.", + code=GPGCode.KEY_REVOKED) elif key.expired: - raise GPGProblem("The key \"" + key.uids[0].uid + "\" is expired.") + raise GPGProblem("The key \"" + key.uids[0].uid + "\" is expired.", + code=GPGCode.KEY_EXPIRED) elif key.invalid: - raise GPGProblem("The key \"" + key.uids[0].uid + "\" is invalid.") + raise GPGProblem("The key \"" + key.uids[0].uid + "\" is invalid.", + code=GPGCode.KEY_INVALID) if encrypt and not key.can_encrypt: - raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not encrypt.") + raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not " + + "encrypt.", code=GPGCode.KEY_CANNOT_ENCRYPT) if sign and not key.can_sign: - raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not sign.") + raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not sign.", + code=GPGCode.KEY_CANNOT_SIGN) |