summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2017-07-16 17:51:39 -0700
committerGitHub <noreply@github.com>2017-07-16 17:51:39 -0700
commit9406ce0379c7aec54a6ac9ba9ae7dc4c785ff082 (patch)
tree42f013545c0758aa0e5d9cdd94d3c39640678b22 /alot
parent5977cf3f43715fe0c22b14d861d6912d4b571c26 (diff)
parent7419687e0a8b882c84e75e7578f4b947d384d413 (diff)
Merge pull request #1081 from dcbaker/submit/crypto-tests
Add crypto module tests
Diffstat (limited to 'alot')
-rw-r--r--alot/crypto.py46
1 files changed, 24 insertions, 22 deletions
diff --git a/alot/crypto.py b/alot/crypto.py
index b0849ae2..4da32eea 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -107,11 +107,10 @@ def get_key(keyid, validate=False, encrypt=False, sign=False,
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)
+ 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
if not valid_key:
@@ -119,29 +118,30 @@ def get_key(keyid, validate=False, encrypt=False, sign=False,
# given action (we don't have private key, they are expired
# etc)
raise GPGProblem(
- "Can not find usable key for \'" +
- keyid +
- "\'.",
+ 'Can not find usable key for "{}".'.format(keyid),
code=GPGCode.NOT_FOUND)
return valid_key
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 "{}".'.format(keyid),
code=GPGCode.NOT_FOUND)
else:
raise e
if signed_only and not check_uid_validity(key, keyid):
- raise GPGProblem("Can not find a trusworthy key for '" + keyid + "'.",
+ raise GPGProblem('Can not find a trusworthy key for "{}".'.format(keyid),
code=GPGCode.NOT_FOUND)
return key
def list_keys(hint=None, private=False):
"""
- Returns a list of all keys containing keyid.
-
- :param keyid: The part we search for
- :param private: Whether secret keys are listed
- :rtype: list
+ Returns a iterator of all keys containing the fingerprint, or all keys if
+ hint is None.
+
+ :param hint: Part of a fingerprint to usee to search
+ :type hint: str or None
+ :param private: Whether to return public keys or secret keys
+ :type private: bool
+ :rtype: :class:`gpgme.KeyIter`
"""
ctx = gpgme.Context()
return ctx.keylist(hint, private)
@@ -261,20 +261,22 @@ 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 "{}" is revoked.'.format(key.uids[0].uid),
code=GPGCode.KEY_REVOKED)
elif key.expired:
- raise GPGProblem("The key \"" + key.uids[0].uid + "\" is expired.",
+ raise GPGProblem('The key "{}" is expired.'.format(key.uids[0].uid),
code=GPGCode.KEY_EXPIRED)
elif key.invalid:
- raise GPGProblem("The key \"" + key.uids[0].uid + "\" is invalid.",
+ raise GPGProblem('The key "{}" is invalid.'.format(key.uids[0].uid),
code=GPGCode.KEY_INVALID)
if encrypt and not key.can_encrypt:
- raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not " +
- "encrypt.", code=GPGCode.KEY_CANNOT_ENCRYPT)
+ raise GPGProblem(
+ 'The key "{}" cannot be used to encrypt'.format(key.uids[0].uid),
+ code=GPGCode.KEY_CANNOT_ENCRYPT)
if sign and not key.can_sign:
- raise GPGProblem("The key \"" + key.uids[0].uid + "\" can not sign.",
- code=GPGCode.KEY_CANNOT_SIGN)
+ raise GPGProblem(
+ 'The key "{}" cannot be used to sign'.format(key.uids[0].uid),
+ code=GPGCode.KEY_CANNOT_SIGN)
def check_uid_validity(key, email):