diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-22 10:12:05 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-22 10:12:05 -0800 |
commit | 1d2901cae193cb965480835aaf96696f8eecfaab (patch) | |
tree | 65ada261aa41bc3000d029480ee2d25f69a22288 /cryptography | |
parent | aafa63cce69c446a0c4d713c8357c61d4a7a8f4e (diff) | |
download | cryptography-1d2901cae193cb965480835aaf96696f8eecfaab.tar.gz cryptography-1d2901cae193cb965480835aaf96696f8eecfaab.tar.bz2 cryptography-1d2901cae193cb965480835aaf96696f8eecfaab.zip |
Hide the dangerous bits
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/fernet.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/cryptography/fernet.py b/cryptography/fernet.py index ae3a8bfa..1c6cb5dd 100644 --- a/cryptography/fernet.py +++ b/cryptography/fernet.py @@ -85,24 +85,22 @@ class Fernet(object): ).encryptor() ciphertext = encryptor.update(padded_data) + encryptor.finalize() + basic_parts = ( + b"\x80" + struct.pack(">Q", current_time) + iv + ciphertext + ) + h = HMAC(self.signing_key, hashes.SHA256(), self.backend) - h.update(b"\x80") - h.update(struct.pack(">Q", current_time)) - h.update(iv) - h.update(ciphertext) + h.update(basic_parts) hmac = h.finalize() - return base64.urlsafe_b64encode( - b"\x80" + struct.pack(">Q", current_time) + iv + ciphertext + hmac - ) + return base64.urlsafe_b64encode(basic_parts + hmac) - def decrypt(self, data, ttl=None, current_time=None): + def decrypt(self, data, ttl=None): if isinstance(data, six.text_type): raise TypeError( "Unicode-objects must be encoded before decryption" ) - if current_time is None: - current_time = int(time.time()) + current_time = int(time.time()) try: data = base64.urlsafe_b64decode(data) |