From 94f9ea25b50a3dd2592abfc63385989955e60e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 27 Feb 2016 00:28:39 +0100 Subject: Add padding check for ANSI X.923 All padding bytes must be 0. --- tests/hazmat/primitives/test_padding.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/hazmat/primitives') diff --git a/tests/hazmat/primitives/test_padding.py b/tests/hazmat/primitives/test_padding.py index 9da8ea7a..9126e5bf 100644 --- a/tests/hazmat/primitives/test_padding.py +++ b/tests/hazmat/primitives/test_padding.py @@ -102,6 +102,21 @@ class TestPKCS7(object): class TestANSIX923(object): + @pytest.mark.parametrize(("size", "padded"), [ + (128, b"1111"), + (128, b"1111111111111111"), + (128, b"111111111111111\x06"), + (128, b"1111111111\x06\x06\x06\x06\x06\x06"), + (128, b""), + (128, b"\x06" * 6), + (128, b"\x00" * 16), + ]) + def test_invalid_padding(self, size, padded): + unpadder = padding.ANSIX923(size).unpadder() + with pytest.raises(ValueError): + unpadder.update(padded) + unpadder.finalize() + @pytest.mark.parametrize(("size", "unpadded", "padded"), [ ( 128, -- cgit v1.2.3