• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5from hypothesis import HealthCheck, given, settings
6from hypothesis.strategies import binary, integers
7
8from cryptography.hazmat.primitives.padding import ANSIX923, PKCS7
9
10
11@settings(suppress_health_check=[HealthCheck.too_slow], deadline=None)
12@given(integers(min_value=1, max_value=255), binary())
13def 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)
17    padder = p.padder()
18    unpadder = p.unpadder()
19
20    padded = padder.update(data) + padder.finalize()
21
22    assert unpadder.update(padded) + unpadder.finalize() == data
23
24
25@settings(suppress_health_check=[HealthCheck.too_slow])
26@given(integers(min_value=1, max_value=255), binary())
27def 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
35