summaryrefslogtreecommitdiff
path: root/alot/crypto.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-08-22 15:24:35 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-08-22 15:24:35 -0700
commit44b7929eadece0130d850b5bd040884a46ba48e5 (patch)
tree644b85de3ff4d62b04eaea5e58a9831459610777 /alot/crypto.py
parent052bd44cd92d79473717806487cbbe4ca3f34bd2 (diff)
crypto: Remove try/except that only applied to pygpgme
list_keys won't raise an exception if there are not keys, it will return a generator that creates an empty list: >>> from alot import crypto >>> list(crypto.list_keys('doesntexist@example.com')) []
Diffstat (limited to 'alot/crypto.py')
-rw-r--r--alot/crypto.py39
1 files changed, 15 insertions, 24 deletions
diff --git a/alot/crypto.py b/alot/crypto.py
index 52eb8c58..f2526c36 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -81,31 +81,22 @@ def get_key(keyid, validate=False, encrypt=False, sign=False,
valid_key = None
- # Catching exceptions for list_keys
- try:
- for k in list_keys(hint=keyid):
- try:
- validate_key(k, encrypt=encrypt, sign=sign)
- except GPGProblem:
- # if the key is invalid for given action skip it
- continue
-
- if valid_key:
- # we have already found one valid key and now we find
- # another? We really received an ambiguous keyid
- raise GPGProblem(
- "More than one key found matching this filter. "
- "Please be more specific "
- "(use a key ID like 4AC8EE1D).",
- code=GPGCode.AMBIGUOUS_NAME)
- valid_key = k
- except gpg.errors.GPGMEError as e:
- # This if will be triggered if there is no key matching at all.
- if e.getcode() == gpg.errors.AMBIGUOUS_NAME:
+ for k in list_keys(hint=keyid):
+ try:
+ validate_key(k, encrypt=encrypt, sign=sign)
+ except GPGProblem:
+ # if the key is invalid for given action skip it
+ continue
+
+ if valid_key:
+ # we have already found one valid key and now we find
+ # another? We really received an ambiguous keyid
raise GPGProblem(
- 'Can not find any key for "{}".'.format(keyid),
- code=GPGCode.NOT_FOUND)
- raise
+ "More than one key found matching this filter. "
+ "Please be more specific "
+ "(use a key ID like 4AC8EE1D).",
+ code=GPGCode.AMBIGUOUS_NAME)
+ valid_key = k
if not valid_key:
# there were multiple keys found but none of them are valid for