aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCédric Krier <ced@b2ck.com>2016-02-26 18:40:20 +0100
committerCédric Krier <ced@b2ck.com>2016-02-27 19:24:40 +0100
commitbf0f464ab62d2e69ebfacd80fad2de46e862fcbc (patch)
tree84c009e637e2d93ebe293847240858a0984798d5 /tests
parentaf95980e394a27355531c9aad474d39253755f81 (diff)
downloadcryptography-bf0f464ab62d2e69ebfacd80fad2de46e862fcbc.tar.gz
cryptography-bf0f464ab62d2e69ebfacd80fad2de46e862fcbc.tar.bz2
cryptography-bf0f464ab62d2e69ebfacd80fad2de46e862fcbc.zip
Added support for padding ANSI X.923
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_padding.py48
-rw-r--r--tests/hypothesis/test_padding.py13
2 files changed, 60 insertions, 1 deletions
diff --git a/tests/hazmat/primitives/test_padding.py b/tests/hazmat/primitives/test_padding.py
index 392ea737..9da8ea7a 100644
--- a/tests/hazmat/primitives/test_padding.py
+++ b/tests/hazmat/primitives/test_padding.py
@@ -99,3 +99,51 @@ class TestPKCS7(object):
unpadder.update(b"")
with pytest.raises(AlreadyFinalized):
unpadder.finalize()
+
+
+class TestANSIX923(object):
+ @pytest.mark.parametrize(("size", "unpadded", "padded"), [
+ (
+ 128,
+ b"1111111111",
+ b"1111111111\x00\x00\x00\x00\x00\x06",
+ ),
+ (
+ 128,
+ b"111111111111111122222222222222",
+ b"111111111111111122222222222222\x00\x02",
+ ),
+ (
+ 128,
+ b"1" * 16,
+ b"1" * 16 + b"\x00" * 15 + b"\x10",
+ ),
+ (
+ 128,
+ b"1" * 17,
+ b"1" * 17 + b"\x00" * 14 + b"\x0F",
+ )
+ ])
+ def test_pad(self, size, unpadded, padded):
+ padder = padding.ANSIX923(size).padder()
+ result = padder.update(unpadded)
+ result += padder.finalize()
+ assert result == padded
+
+ @pytest.mark.parametrize(("size", "unpadded", "padded"), [
+ (
+ 128,
+ b"1111111111",
+ b"1111111111\x00\x00\x00\x00\x00\x06",
+ ),
+ (
+ 128,
+ b"111111111111111122222222222222",
+ b"111111111111111122222222222222\x00\x02",
+ ),
+ ])
+ def test_unpad(self, size, unpadded, padded):
+ unpadder = padding.ANSIX923(size).unpadder()
+ result = unpadder.update(padded)
+ result += unpadder.finalize()
+ assert result == unpadded
diff --git a/tests/hypothesis/test_padding.py b/tests/hypothesis/test_padding.py
index 21c9a234..29d726f1 100644
--- a/tests/hypothesis/test_padding.py
+++ b/tests/hypothesis/test_padding.py
@@ -5,7 +5,7 @@
from hypothesis import given
from hypothesis.strategies import binary, integers
-from cryptography.hazmat.primitives.padding import PKCS7
+from cryptography.hazmat.primitives.padding import ANSIX923, PKCS7
@given(integers(min_value=1, max_value=31), binary())
@@ -19,3 +19,14 @@ def test_pkcs7(block_size, data):
padded = padder.update(data) + padder.finalize()
assert unpadder.update(padded) + unpadder.finalize() == data
+
+
+@given(integers(min_value=1, max_value=31), binary())
+def test_ansix923(block_size, data):
+ a = ANSIX923(block_size=block_size * 8)
+ padder = a.padder()
+ unpadder = a.unpadder()
+
+ padded = padder.update(data) + padder.finalize()
+
+ assert unpadder.update(padded) + unpadder.finalize() == data