aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAyrx <terrycwk1994@gmail.com>2014-05-17 19:47:09 +0800
committerAyrx <terrycwk1994@gmail.com>2014-05-17 19:47:09 +0800
commit00eff9ca7fece942670429824cb77dd532190c96 (patch)
tree6fdc0df70cd1bbecd56049208899111a8edcd202 /cryptography
parent6d69eab6caff7b87d32fab3c7178296e481eb8a4 (diff)
downloadcryptography-00eff9ca7fece942670429824cb77dd532190c96.tar.gz
cryptography-00eff9ca7fece942670429824cb77dd532190c96.tar.bz2
cryptography-00eff9ca7fece942670429824cb77dd532190c96.zip
Simplified exception message
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/fernet.py10
-rw-r--r--cryptography/hazmat/primitives/cmac.py10
-rw-r--r--cryptography/hazmat/primitives/constant_time.py5
-rw-r--r--cryptography/hazmat/primitives/hashes.py5
-rw-r--r--cryptography/hazmat/primitives/hmac.py10
-rw-r--r--cryptography/hazmat/primitives/kdf/hkdf.py20
-rw-r--r--cryptography/hazmat/primitives/kdf/pbkdf2.py10
-rw-r--r--cryptography/hazmat/primitives/padding.py10
8 files changed, 16 insertions, 64 deletions
diff --git a/cryptography/fernet.py b/cryptography/fernet.py
index d0394b41..93eb32bd 100644
--- a/cryptography/fernet.py
+++ b/cryptography/fernet.py
@@ -61,10 +61,7 @@ class Fernet(object):
def _encrypt_from_parts(self, data, current_time, iv):
if not isinstance(data, six.binary_type):
- raise TypeError(
- "data must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("data must be bytes")
padder = padding.PKCS7(algorithms.AES.block_size).padder()
padded_data = padder.update(data) + padder.finalize()
@@ -84,10 +81,7 @@ class Fernet(object):
def decrypt(self, token, ttl=None):
if not isinstance(token, six.binary_type):
- raise TypeError(
- "token must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("token must be bytes")
current_time = int(time.time())
diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py
index cc8e8f2c..b01c5170 100644
--- a/cryptography/hazmat/primitives/cmac.py
+++ b/cryptography/hazmat/primitives/cmac.py
@@ -48,10 +48,7 @@ class CMAC(object):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")
if not isinstance(data, six.binary_type):
- raise TypeError(
- "data must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("data must be bytes")
self._ctx.update(data)
def finalize(self):
@@ -63,10 +60,7 @@ class CMAC(object):
def verify(self, signature):
if not isinstance(signature, six.binary_type):
- raise TypeError(
- "signature must be binary type. This is str in Python 2 and "
- "bytes in Python 3"
- )
+ raise TypeError("signature must be bytes")
digest = self.finalize()
if not constant_time.bytes_eq(digest, signature):
raise InvalidSignature("Signature did not match digest.")
diff --git a/cryptography/hazmat/primitives/constant_time.py b/cryptography/hazmat/primitives/constant_time.py
index 658b1f5f..6d325a9d 100644
--- a/cryptography/hazmat/primitives/constant_time.py
+++ b/cryptography/hazmat/primitives/constant_time.py
@@ -59,9 +59,6 @@ _lib = _ffi.verify(
def bytes_eq(a, b):
if (not isinstance(a, six.binary_type) or
not isinstance(b, six.binary_type)):
- raise TypeError(
- "a and b must be binary type. This is str in Python 2 and "
- "bytes in Python 3"
- )
+ raise TypeError("a and b must be bytes")
return _lib.Cryptography_constant_time_bytes_eq(a, len(a), b, len(b)) == 1
diff --git a/cryptography/hazmat/primitives/hashes.py b/cryptography/hazmat/primitives/hashes.py
index a9b5b55a..2efd8484 100644
--- a/cryptography/hazmat/primitives/hashes.py
+++ b/cryptography/hazmat/primitives/hashes.py
@@ -47,10 +47,7 @@ class Hash(object):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")
if not isinstance(data, six.binary_type):
- raise TypeError(
- "data must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("data must be bytes")
self._ctx.update(data)
def copy(self):
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index e39fcf89..5d7bad59 100644
--- a/cryptography/hazmat/primitives/hmac.py
+++ b/cryptography/hazmat/primitives/hmac.py
@@ -47,10 +47,7 @@ class HMAC(object):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")
if not isinstance(msg, six.binary_type):
- raise TypeError(
- "msg must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("msg must be bytes")
self._ctx.update(msg)
def copy(self):
@@ -72,10 +69,7 @@ class HMAC(object):
def verify(self, signature):
if not isinstance(signature, six.binary_type):
- raise TypeError(
- "signature must be binary type. This is str in Python 2 and "
- "bytes in Python 3"
- )
+ raise TypeError("signature must be bytes")
digest = self.finalize()
if not constant_time.bytes_eq(digest, signature):
raise InvalidSignature("Signature did not match digest.")
diff --git a/cryptography/hazmat/primitives/kdf/hkdf.py b/cryptography/hazmat/primitives/kdf/hkdf.py
index e02d9aff..adeecaff 100644
--- a/cryptography/hazmat/primitives/kdf/hkdf.py
+++ b/cryptography/hazmat/primitives/kdf/hkdf.py
@@ -35,10 +35,7 @@ class HKDF(object):
self._algorithm = algorithm
if not isinstance(salt, six.binary_type) and salt is not None:
- raise TypeError(
- "salt must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("salt must be bytes")
if salt is None:
salt = b"\x00" * (self._algorithm.digest_size // 8)
@@ -56,10 +53,7 @@ class HKDF(object):
def derive(self, key_material):
if not isinstance(key_material, six.binary_type):
- raise TypeError(
- "key_material must be binary type. This is str in Python 2 "
- "and bytes in Python 3"
- )
+ raise TypeError("key_material must be bytes")
return self._hkdf_expand.derive(self._extract(key_material))
@@ -92,10 +86,7 @@ class HKDFExpand(object):
self._length = length
if not isinstance(info, six.binary_type) and info is not None:
- raise TypeError(
- "info must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("info must be bytes")
if info is None:
info = b""
@@ -120,10 +111,7 @@ class HKDFExpand(object):
def derive(self, key_material):
if not isinstance(key_material, six.binary_type):
- raise TypeError(
- "key_material must be binary type. This is str in Python 2 "
- "and bytes in Python 3"
- )
+ raise TypeError("key_material must be bytes")
if self._used:
raise AlreadyFinalized
diff --git a/cryptography/hazmat/primitives/kdf/pbkdf2.py b/cryptography/hazmat/primitives/kdf/pbkdf2.py
index 6711763d..66a9b462 100644
--- a/cryptography/hazmat/primitives/kdf/pbkdf2.py
+++ b/cryptography/hazmat/primitives/kdf/pbkdf2.py
@@ -42,10 +42,7 @@ class PBKDF2HMAC(object):
self._algorithm = algorithm
self._length = length
if not isinstance(salt, six.binary_type):
- raise TypeError(
- "salt must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("salt must be bytes")
self._salt = salt
self._iterations = iterations
self._backend = backend
@@ -56,10 +53,7 @@ class PBKDF2HMAC(object):
self._used = True
if not isinstance(key_material, six.binary_type):
- raise TypeError(
- "key_material must be binary type. This is str in Python 2 "
- "and bytes in Python 3"
- )
+ raise TypeError("key_material must be bytes")
return self._backend.derive_pbkdf2_hmac(
self._algorithm,
self._length,
diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py
index 982baaee..e8e6a6df 100644
--- a/cryptography/hazmat/primitives/padding.py
+++ b/cryptography/hazmat/primitives/padding.py
@@ -105,10 +105,7 @@ class _PKCS7PaddingContext(object):
raise AlreadyFinalized("Context was already finalized")
if not isinstance(data, six.binary_type):
- raise TypeError(
- "data must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("data must be bytes")
self._buffer += data
@@ -141,10 +138,7 @@ class _PKCS7UnpaddingContext(object):
raise AlreadyFinalized("Context was already finalized")
if not isinstance(data, six.binary_type):
- raise TypeError(
- "data must be binary type. This is str in Python 2 and bytes "
- "in Python 3"
- )
+ raise TypeError("data must be bytes")
self._buffer += data