summaryrefslogtreecommitdiff
path: root/src/leap/common/keymanager
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/common/keymanager')
-rw-r--r--src/leap/common/keymanager/__init__.py2
-rw-r--r--src/leap/common/keymanager/errors.py5
-rw-r--r--src/leap/common/keymanager/openpgp.py19
3 files changed, 17 insertions, 9 deletions
diff --git a/src/leap/common/keymanager/__init__.py b/src/leap/common/keymanager/__init__.py
index d6dbb8a..ab28510 100644
--- a/src/leap/common/keymanager/__init__.py
+++ b/src/leap/common/keymanager/__init__.py
@@ -116,7 +116,7 @@ class KeyManager(object):
leap_assert(response.status_code == 200, 'Invalid response.')
leap_assert(
response.headers['content-type'].startswith('application/json')
- is True,
+ is True,
'Content-type is not JSON.')
return response.json()
diff --git a/src/leap/common/keymanager/errors.py b/src/leap/common/keymanager/errors.py
index f712975..d6802f0 100644
--- a/src/leap/common/keymanager/errors.py
+++ b/src/leap/common/keymanager/errors.py
@@ -42,6 +42,7 @@ class KeyAttributesDiffer(Exception):
"""
pass
+
class NoPasswordGiven(Exception):
"""
Raised when trying to perform some action that needs a password without
@@ -49,24 +50,28 @@ class NoPasswordGiven(Exception):
"""
pass
+
class InvalidSignature(Exception):
"""
Raised when signature could not be verified.
"""
pass
+
class EncryptionFailed(Exception):
"""
Raised upon failures of encryption.
"""
pass
+
class DecryptionFailed(Exception):
"""
Raised upon failures of decryption.
"""
pass
+
class SignFailed(Exception):
"""
Raised when failed to sign.
diff --git a/src/leap/common/keymanager/openpgp.py b/src/leap/common/keymanager/openpgp.py
index 0cb1308..d578638 100644
--- a/src/leap/common/keymanager/openpgp.py
+++ b/src/leap/common/keymanager/openpgp.py
@@ -66,7 +66,7 @@ def encrypt_sym(data, passphrase, sign=None):
leap_assert_type(passphrase, str)
if sign is not None:
leap_assert_type(sign, OpenPGPKey)
- leap_assert(sign.private == True)
+ leap_assert(sign.private is True)
def _encrypt_cb(gpg):
result = gpg.encrypt(
@@ -105,7 +105,7 @@ def decrypt_sym(data, passphrase, verify=None):
leap_assert_type(passphrase, str)
if verify is not None:
leap_assert_type(verify, OpenPGPKey)
- leap_assert(verify.private == False)
+ leap_assert(verify.private is False)
def _decrypt_cb(gpg):
result = gpg.decrypt(data, passphrase=passphrase)
@@ -145,7 +145,7 @@ def encrypt_asym(data, pubkey, sign=None):
leap_assert(pubkey.private is False, 'Key is not public.')
if sign is not None:
leap_assert_type(sign, OpenPGPKey)
- leap_assert(sign.private == True)
+ leap_assert(sign.private is True)
def _encrypt_cb(gpg):
result = gpg.encrypt(
@@ -185,7 +185,7 @@ def decrypt_asym(data, privkey, verify=None):
leap_assert(privkey.private is True, 'Key is not private.')
if verify is not None:
leap_assert_type(verify, OpenPGPKey)
- leap_assert(verify.private == False)
+ leap_assert(verify.private is False)
def _decrypt_cb(gpg):
result = gpg.decrypt(data)
@@ -258,6 +258,7 @@ def is_encrypted_asym(data):
return _safe_call(_is_encrypted_cb)
+
def sign(data, privkey):
"""
Sign C{data} with C{privkey}.
@@ -271,7 +272,7 @@ def sign(data, privkey):
@rtype: str
"""
leap_assert_type(privkey, OpenPGPKey)
- leap_assert(privkey.private == True)
+ leap_assert(privkey.private is True)
def _sign_cb(gpg):
result = gpg.sign(data, keyid=privkey.key_id)
@@ -289,6 +290,7 @@ def sign(data, privkey):
return _safe_call(_sign_cb, [privkey])
+
def verify(data, pubkey):
"""
Verify signed C{data} with C{pubkey}.
@@ -302,7 +304,7 @@ def verify(data, pubkey):
@rtype: str
"""
leap_assert_type(pubkey, OpenPGPKey)
- leap_assert(pubkey.private == False)
+ leap_assert(pubkey.private is False)
def _verify_cb(gpg):
result = gpg.verify(data)
@@ -314,6 +316,7 @@ def verify(data, pubkey):
return _safe_call(_verify_cb, [pubkey])
+
#
# Helper functions
#
@@ -358,8 +361,8 @@ def _build_keyring(keys=[]):
@return: A GPG wrapper with a unitary keyring.
@rtype: gnupg.GPG
"""
- privkeys = filter(lambda key: key.private == True, keys)
- pubkeys = filter(lambda key: key.private == False, keys)
+ privkeys = filter(lambda key: key.private is True, keys)
+ pubkeys = filter(lambda key: key.private is False, keys)
# here we filter out public keys that have a correspondent private key in
# the list because the private key_data by itself is enough to also have
# the public key in the keyring, and we want to count the keys afterwards.