aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 12:52:18 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 12:52:18 -0800
commit0ab3e44b0512a6cbab845a65759a21787bf15d27 (patch)
treefd99b446da8b331d5215e35cbf20dacdc8e519a5 /tests
parent838ad7d2f5bb97242a9f75ac9055be5be75a7711 (diff)
downloadcryptography-0ab3e44b0512a6cbab845a65759a21787bf15d27.tar.gz
cryptography-0ab3e44b0512a6cbab845a65759a21787bf15d27.tar.bz2
cryptography-0ab3e44b0512a6cbab845a65759a21787bf15d27.zip
Raise a correct error when content isn't padded correctly
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_block.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index 9460c53d..4c756203 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -18,7 +18,9 @@ import binascii
import pytest
from cryptography import utils
-from cryptography.exceptions import UnsupportedAlgorithm, AlreadyFinalized
+from cryptography.exceptions import (
+ UnsupportedAlgorithm, AlreadyFinalized, IncorrectPadding
+)
from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers import (
Cipher, algorithms, modes
@@ -108,3 +110,19 @@ class TestCipherContext(object):
with pytest.raises(UnsupportedAlgorithm):
cipher.decryptor()
+
+ def test_incorrectly_padded(self, backend):
+ cipher = Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CBC(b"\x00" * 16),
+ backend
+ )
+ encryptor = cipher.encryptor()
+ encryptor.update(b"1")
+ with pytest.raises(IncorrectPadding):
+ encryptor.finalize()
+
+ decryptor = cipher.decryptor()
+ decryptor.update(b"1")
+ with pytest.raises(IncorrectPadding):
+ decryptor.finalize()