aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-12-16 15:44:06 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-12-16 15:44:06 -0800
commita8f0b63dddc6a22a1a982c6217d4cef2f598b781 (patch)
treecfaefed672494fc6f4076655adf67136708ecbdb /cryptography
parentfae20715b85e84297f01b60fc153cde93a7549c7 (diff)
downloadcryptography-a8f0b63dddc6a22a1a982c6217d4cef2f598b781.tar.gz
cryptography-a8f0b63dddc6a22a1a982c6217d4cef2f598b781.tar.bz2
cryptography-a8f0b63dddc6a22a1a982c6217d4cef2f598b781.zip
Replace assertions with real error checks
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/fernet.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/cryptography/fernet.py b/cryptography/fernet.py
index c0c5631f..c5474af4 100644
--- a/cryptography/fernet.py
+++ b/cryptography/fernet.py
@@ -38,7 +38,10 @@ class Fernet(object):
backend = default_backend()
key = base64.urlsafe_b64decode(key)
- assert len(key) == 32
+ if len(key) != 32:
+ raise ValueError(
+ "Fernet key must be 32 url-safe base64-encoded bytes"
+ )
self._signing_key = key[:16]
self._encryption_key = key[16:]
@@ -88,7 +91,9 @@ class Fernet(object):
except (TypeError, binascii.Error):
raise InvalidToken
- assert six.indexbytes(data, 0) == 0x80
+ if six.indexbytes(data, 0) != 0x80:
+ raise InvalidToken
+
timestamp = struct.unpack(">Q", data[1:9])[0]
iv = data[9:25]
ciphertext = data[25:-32]