summaryrefslogtreecommitdiff
path: root/alot/crypto.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-05-13 12:22:44 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-13 12:22:44 +0100
commit3ca453f6313ea328a3c465630b260b13eba6a097 (patch)
tree4d24e476d8a4bb2a6447cc8cf0b4a9fd20dd5c9a /alot/crypto.py
parent0375b095f16d20f7034f5932e022ec6c1ce6cd7a (diff)
make CryptoContext.get_key fail if no key found
this makes CryptoContext.get_key raise a GPGProblem exception in case no key could be found. It obsoletes otherwise necessary tests for its return value to be not None.
Diffstat (limited to 'alot/crypto.py')
-rw-r--r--alot/crypto.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/alot/crypto.py b/alot/crypto.py
index c80fff8f..4e38a472 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -87,10 +87,12 @@ class CryptoContext(pyme.core.Context):
Gets a key from the keyring by filtering for the specified keyid, but
only if the given keyid is specific enough (if it matches multiple
keys, an exception will be thrown).
+ The same happens if no key is found for the given hint.
:param keyid: filter term for the keyring (usually a key ID)
:type keyid: bytestring
:rtype: pyme.pygpgme._gpgme_key
+ :raises: GPGProblem
"""
result = self.op_keylist_start(str(keyid), 0)
key = self.op_keylist_next()
@@ -98,6 +100,8 @@ class CryptoContext(pyme.core.Context):
raise GPGProblem(("More than one key found matching this filter."
" Please be more specific (use a key ID like 4AC8EE1D)."))
self.op_keylist_end()
+ if key == None:
+ raise GPGProblem('No key could be found for hint "%s"' % keyid)
return key
def detached_signature_for(self, plaintext_str, key=None):