blob: 74a58eb8c2c5f28ef8e69065356ed292b51f746d [file] [log] [blame]
Alex Gaynorb3016272016-01-13 09:01:42 -05001# 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
Paul Kehrerfec083e2018-11-12 08:02:52 -05005from hypothesis import HealthCheck, given, settings
Alex Gaynor3066bf42016-01-13 22:22:18 -05006from hypothesis.strategies import binary, integers
Alex Gaynorb3016272016-01-13 09:01:42 -05007
Cédric Krierbf0f4642016-02-26 18:40:20 +01008from cryptography.hazmat.primitives.padding import ANSIX923, PKCS7
Alex Gaynorb3016272016-01-13 09:01:42 -05009
10
Paul Kehrerc33ef912019-01-15 23:56:42 -060011@settings(suppress_health_check=[HealthCheck.too_slow], deadline=None)
Terry Chiae9b87d52016-11-15 09:56:02 +080012@given(integers(min_value=1, max_value=255), binary())
Alex Gaynor3066bf42016-01-13 22:22:18 -050013def test_pkcs7(block_size, data):
14 # Generate in [1, 31] so we can easily get block_size in bits by
15 # multiplying by 8.
16 p = PKCS7(block_size=block_size * 8)
Alex Gaynorb3016272016-01-13 09:01:42 -050017 padder = p.padder()
18 unpadder = p.unpadder()
19
20 padded = padder.update(data) + padder.finalize()
21
22 assert unpadder.update(padded) + unpadder.finalize() == data
Cédric Krierbf0f4642016-02-26 18:40:20 +010023
24
Paul Kehrerfec083e2018-11-12 08:02:52 -050025@settings(suppress_health_check=[HealthCheck.too_slow])
Terry Chiae9b87d52016-11-15 09:56:02 +080026@given(integers(min_value=1, max_value=255), binary())
Cédric Krierbf0f4642016-02-26 18:40:20 +010027def test_ansix923(block_size, data):
28 a = ANSIX923(block_size=block_size * 8)
29 padder = a.padder()
30 unpadder = a.unpadder()
31
32 padded = padder.update(data) + padder.finalize()
33
34 assert unpadder.update(padded) + unpadder.finalize() == data