aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 17:27:08 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 17:27:08 -0800
commit09bff867916af9694d66c2fea917d192f7dd1a25 (patch)
treedbd0d0290ffd61779b3e9c8ce60369173633ccad /cryptography
parent56e78a942e71faac27d1b6451d6c409ee559a1f1 (diff)
downloadcryptography-09bff867916af9694d66c2fea917d192f7dd1a25.tar.gz
cryptography-09bff867916af9694d66c2fea917d192f7dd1a25.tar.bz2
cryptography-09bff867916af9694d66c2fea917d192f7dd1a25.zip
Handle another error case
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/fernet.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/cryptography/fernet.py b/cryptography/fernet.py
index efa13b8f..aa46b36f 100644
--- a/cryptography/fernet.py
+++ b/cryptography/fernet.py
@@ -129,7 +129,11 @@ class Fernet(object):
decryptor = Cipher(
algorithms.AES(self.encryption_key), modes.CBC(iv), self.backend
).decryptor()
- plaintext_padded = decryptor.update(ciphertext) + decryptor.finalize()
+ plaintext_padded = decryptor.update(ciphertext)
+ try:
+ plaintext_padded += decryptor.finalize()
+ except ValueError:
+ raise InvalidToken
unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
unpadded = unpadder.update(plaintext_padded)