Alex Gaynor | b301627 | 2016-01-13 09:01:42 -0500 | [diff] [blame] | 1 | # This file is dual licensed under the terms of the Apache License, Version |
| 2 | # 2.0, and the BSD License. See the LICENSE file in the root of this repository |
| 3 | # for complete details. |
| 4 | |
| 5 | from hypothesis import given |
Alex Gaynor | 3066bf4 | 2016-01-13 22:22:18 -0500 | [diff] [blame^] | 6 | from hypothesis.strategies import binary, integers |
Alex Gaynor | b301627 | 2016-01-13 09:01:42 -0500 | [diff] [blame] | 7 | |
| 8 | from cryptography.hazmat.primitives.padding import PKCS7 |
| 9 | |
| 10 | |
Alex Gaynor | 3066bf4 | 2016-01-13 22:22:18 -0500 | [diff] [blame^] | 11 | @given(integers(min_value=1, max_value=31), binary()) |
| 12 | def test_pkcs7(block_size, data): |
| 13 | # Generate in [1, 31] so we can easily get block_size in bits by |
| 14 | # multiplying by 8. |
| 15 | p = PKCS7(block_size=block_size * 8) |
Alex Gaynor | b301627 | 2016-01-13 09:01:42 -0500 | [diff] [blame] | 16 | padder = p.padder() |
| 17 | unpadder = p.unpadder() |
| 18 | |
| 19 | padded = padder.update(data) + padder.finalize() |
| 20 | |
| 21 | assert unpadder.update(padded) + unpadder.finalize() == data |