diff options
author | Cédric Krier <ced@b2ck.com> | 2016-03-16 08:34:25 +0100 |
---|---|---|
committer | Cédric Krier <ced@b2ck.com> | 2016-03-16 08:34:25 +0100 |
commit | 70b3a7dd5ce2a953da1ce19534bcedbb53a8c2bf (patch) | |
tree | acced34d47e390f4b8e253b4f4bc62e354192826 /tests/hazmat/primitives | |
parent | 6cfd9192b7c76dce2979e72f77fae2d653d58ebe (diff) | |
download | cryptography-70b3a7dd5ce2a953da1ce19534bcedbb53a8c2bf.tar.gz cryptography-70b3a7dd5ce2a953da1ce19534bcedbb53a8c2bf.tar.bz2 cryptography-70b3a7dd5ce2a953da1ce19534bcedbb53a8c2bf.zip |
Add more tests since there is no more sub-classing
Diffstat (limited to 'tests/hazmat/primitives')
-rw-r--r-- | tests/hazmat/primitives/test_padding.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_padding.py b/tests/hazmat/primitives/test_padding.py index 9126e5bf..e934c0ac 100644 --- a/tests/hazmat/primitives/test_padding.py +++ b/tests/hazmat/primitives/test_padding.py @@ -102,6 +102,11 @@ class TestPKCS7(object): class TestANSIX923(object): + @pytest.mark.parametrize("size", [127, 4096, -2]) + def test_invalid_block_size(self, size): + with pytest.raises(ValueError): + padding.ANSIX923(size) + @pytest.mark.parametrize(("size", "padded"), [ (128, b"1111"), (128, b"1111111111111111"), @@ -117,6 +122,14 @@ class TestANSIX923(object): unpadder.update(padded) unpadder.finalize() + def test_non_bytes(self): + padder = padding.ANSIX923(128).padder() + with pytest.raises(TypeError): + padder.update(u"abc") + unpadder = padding.ANSIX923(128).unpadder() + with pytest.raises(TypeError): + unpadder.update(u"abc") + @pytest.mark.parametrize(("size", "unpadded", "padded"), [ ( 128, @@ -162,3 +175,19 @@ class TestANSIX923(object): result = unpadder.update(padded) result += unpadder.finalize() assert result == unpadded + + def test_use_after_finalize(self): + padder = padding.ANSIX923(128).padder() + b = padder.finalize() + with pytest.raises(AlreadyFinalized): + padder.update(b"") + with pytest.raises(AlreadyFinalized): + padder.finalize() + + unpadder = padding.ANSIX923(128).unpadder() + unpadder.update(b) + unpadder.finalize() + with pytest.raises(AlreadyFinalized): + unpadder.update(b"") + with pytest.raises(AlreadyFinalized): + unpadder.finalize() |