aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 11:59:30 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 11:59:30 -0700
commitbd458ae1e3bdd48f74437216ac467ab2e4d68b13 (patch)
tree5fd13fa170b10e992595abdf279d2f5a8d46025f /tests
parent1fe70b12b24f1180b2c4fde1764e309bc0cb338d (diff)
downloadcryptography-bd458ae1e3bdd48f74437216ac467ab2e4d68b13.tar.gz
cryptography-bd458ae1e3bdd48f74437216ac467ab2e4d68b13.tar.bz2
cryptography-bd458ae1e3bdd48f74437216ac467ab2e4d68b13.zip
Missed file
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/utils.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/primitives/utils.py b/tests/primitives/utils.py
new file mode 100644
index 00000000..e35c915a
--- /dev/null
+++ b/tests/primitives/utils.py
@@ -0,0 +1,40 @@
+import binascii
+import os
+
+import pytest
+
+from cryptography.bindings import openssl
+from cryptography.primitives.block import BlockCipher
+
+
+def generate_encrypt_test(param_loader, cipher_name, vector_type, file_names,
+ cipher_factory, mode_factory,
+ only_if=lambda api: True):
+ def test_encryption(self):
+ for api in [openssl.api]:
+ if not only_if(api):
+ yield encrypt_skipped
+ else:
+ for file_name in file_names:
+ for params in param_loader(
+ os.path.join(cipher_name, vector_type, file_name)
+ ):
+ yield encrypt_test, api, cipher_factory, mode_factory, params
+ return test_encryption
+
+
+def encrypt_test(api, cipher_factory, mode_factory, params):
+ plaintext = params.pop("plaintext")
+ ciphertext = params.pop("ciphertext")
+ cipher = BlockCipher(
+ cipher_factory(**params),
+ mode_factory(**params),
+ api
+ )
+ actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
+ actual_ciphertext += cipher.finalize()
+ assert binascii.hexlify(actual_ciphertext) == ciphertext
+
+
+def encrypt_skipped():
+ pytest.skip("because reasons")