aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bindings/test_openssl.py12
-rw-r--r--tests/conftest.py6
-rw-r--r--tests/primitives/test_block.py10
-rw-r--r--tests/primitives/test_cryptrec.py2
-rw-r--r--tests/primitives/test_hash_vectors.py20
-rw-r--r--tests/primitives/test_hashes.py24
-rw-r--r--tests/primitives/test_openssl_vectors.py8
-rw-r--r--tests/primitives/test_utils.py8
-rw-r--r--tests/primitives/utils.py48
9 files changed, 69 insertions, 69 deletions
diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py
index bf201e4d..bdfbed36 100644
--- a/tests/bindings/test_openssl.py
+++ b/tests/bindings/test_openssl.py
@@ -13,14 +13,14 @@
import pytest
-from cryptography.bindings.openssl.api import api
+from cryptography.bindings.openssl.backend import backend
from cryptography.primitives.block.ciphers import AES
from cryptography.primitives.block.modes import CBC
class TestOpenSSL(object):
- def test_api_exists(self):
- assert api
+ def test_backend_exists(self):
+ assert backend
def test_openssl_version_text(self):
"""
@@ -31,11 +31,11 @@ class TestOpenSSL(object):
if it starts with OpenSSL as that appears to be true
for every OpenSSL.
"""
- assert api.openssl_version_text().startswith("OpenSSL")
+ assert backend.openssl_version_text().startswith("OpenSSL")
def test_supports_cipher(self):
- assert api.supports_cipher(None, None) is False
+ assert backend.supports_cipher(None, None) is False
def test_register_duplicate_cipher_adapter(self):
with pytest.raises(ValueError):
- api.register_cipher_adapter(AES, CBC, None)
+ backend.register_cipher_adapter(AES, CBC, None)
diff --git a/tests/conftest.py b/tests/conftest.py
index b526f2bf..d2ba03de 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,5 @@
def pytest_generate_tests(metafunc):
- from cryptography.bindings import _ALL_APIS
+ from cryptography.bindings import _ALL_BACKENDS
- if "api" in metafunc.fixturenames:
- metafunc.parametrize("api", _ALL_APIS)
+ if "backend" in metafunc.fixturenames:
+ metafunc.parametrize("backend", _ALL_BACKENDS)
diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py
index 5e147a79..3b3b1f91 100644
--- a/tests/primitives/test_block.py
+++ b/tests/primitives/test_block.py
@@ -22,7 +22,7 @@ from cryptography.primitives.block import BlockCipher, ciphers, modes
class TestBlockCipher(object):
- def test_instantiate_without_api(self):
+ def test_instantiate_without_backend(self):
BlockCipher(
ciphers.AES(binascii.unhexlify(b"0" * 32)),
modes.CBC(binascii.unhexlify(b"0" * 32))
@@ -44,11 +44,11 @@ class TestBlockCipher(object):
class TestBlockCipherContext(object):
- def test_use_after_finalize(self, api):
+ def test_use_after_finalize(self, backend):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(b"0" * 32)),
modes.CBC(binascii.unhexlify(b"0" * 32)),
- api
+ backend
)
encryptor = cipher.encryptor()
encryptor.update(b"a" * 16)
@@ -65,11 +65,11 @@ class TestBlockCipherContext(object):
with pytest.raises(ValueError):
decryptor.finalize()
- def test_unaligned_block_encryption(self, api):
+ def test_unaligned_block_encryption(self, backend):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(b"0" * 32)),
modes.ECB(),
- api
+ backend
)
encryptor = cipher.encryptor()
ct = encryptor.update(b"a" * 15)
diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py
index 02a04473..d8c9aaa3 100644
--- a/tests/primitives/test_cryptrec.py
+++ b/tests/primitives/test_cryptrec.py
@@ -37,7 +37,7 @@ class TestCamelliaECB(object):
],
lambda key: ciphers.Camellia(binascii.unhexlify((key))),
lambda key: modes.ECB(),
- only_if=lambda api: api.supports_cipher(
+ only_if=lambda backend: backend.supports_cipher(
ciphers.Camellia("\x00" * 16), modes.ECB()
),
skip_message="Does not support Camellia ECB",
diff --git a/tests/primitives/test_hash_vectors.py b/tests/primitives/test_hash_vectors.py
index 02ef4dbb..b42021c9 100644
--- a/tests/primitives/test_hash_vectors.py
+++ b/tests/primitives/test_hash_vectors.py
@@ -30,7 +30,7 @@ class TestSHA1(object):
"SHA1ShortMsg.rsp",
],
hashes.SHA1,
- only_if=lambda api: api.supports_hash(hashes.SHA1),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA1),
skip_message="Does not support SHA1",
)
@@ -44,7 +44,7 @@ class TestSHA224(object):
"SHA224ShortMsg.rsp",
],
hashes.SHA224,
- only_if=lambda api: api.supports_hash(hashes.SHA224),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA224),
skip_message="Does not support SHA224",
)
@@ -58,7 +58,7 @@ class TestSHA256(object):
"SHA256ShortMsg.rsp",
],
hashes.SHA256,
- only_if=lambda api: api.supports_hash(hashes.SHA256),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA256),
skip_message="Does not support SHA256",
)
@@ -72,7 +72,7 @@ class TestSHA384(object):
"SHA384ShortMsg.rsp",
],
hashes.SHA384,
- only_if=lambda api: api.supports_hash(hashes.SHA384),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA384),
skip_message="Does not support SHA384",
)
@@ -86,7 +86,7 @@ class TestSHA512(object):
"SHA512ShortMsg.rsp",
],
hashes.SHA512,
- only_if=lambda api: api.supports_hash(hashes.SHA512),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA512),
skip_message="Does not support SHA512",
)
@@ -99,14 +99,14 @@ class TestRIPEMD160(object):
"ripevectors.txt",
],
hashes.RIPEMD160,
- only_if=lambda api: api.supports_hash(hashes.RIPEMD160),
+ only_if=lambda backend: backend.supports_hash(hashes.RIPEMD160),
skip_message="Does not support RIPEMD160",
)
test_RIPEMD160_long_string = generate_long_string_hash_test(
hashes.RIPEMD160,
"52783243c1697bdbe16d37f97f68f08325dc1528",
- only_if=lambda api: api.supports_hash(hashes.RIPEMD160),
+ only_if=lambda backend: backend.supports_hash(hashes.RIPEMD160),
skip_message="Does not support RIPEMD160",
)
@@ -119,7 +119,7 @@ class TestWhirlpool(object):
"iso-test-vectors.txt",
],
hashes.Whirlpool,
- only_if=lambda api: api.supports_hash(hashes.Whirlpool),
+ only_if=lambda backend: backend.supports_hash(hashes.Whirlpool),
skip_message="Does not support Whirlpool",
)
@@ -128,7 +128,7 @@ class TestWhirlpool(object):
("0c99005beb57eff50a7cf005560ddf5d29057fd86b2"
"0bfd62deca0f1ccea4af51fc15490eddc47af32bb2b"
"66c34ff9ad8c6008ad677f77126953b226e4ed8b01"),
- only_if=lambda api: api.supports_hash(hashes.Whirlpool),
+ only_if=lambda backend: backend.supports_hash(hashes.Whirlpool),
skip_message="Does not support Whirlpool",
)
@@ -141,6 +141,6 @@ class TestMD5(object):
"rfc-1321.txt",
],
hashes.MD5,
- only_if=lambda api: api.supports_hash(hashes.MD5),
+ only_if=lambda backend: backend.supports_hash(hashes.MD5),
skip_message="Does not support MD5",
)
diff --git a/tests/primitives/test_hashes.py b/tests/primitives/test_hashes.py
index 03de8916..505f6c8a 100644
--- a/tests/primitives/test_hashes.py
+++ b/tests/primitives/test_hashes.py
@@ -23,13 +23,13 @@ from .utils import generate_base_hash_test
class TestBaseHash(object):
- def test_base_hash_reject_unicode(self, api):
- m = hashes.SHA1(api=api)
+ def test_base_hash_reject_unicode(self, backend):
+ m = hashes.SHA1(backend=backend)
with pytest.raises(TypeError):
m.update(six.u("\u00FC"))
- def test_base_hash_hexdigest_string_type(self, api):
- m = hashes.SHA1(api=api, data=b"")
+ def test_base_hash_hexdigest_string_type(self, backend):
+ m = hashes.SHA1(backend=backend, data=b"")
assert isinstance(m.hexdigest(), str)
@@ -38,7 +38,7 @@ class TestSHA1(object):
hashes.SHA1,
digest_size=20,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.SHA1),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA1),
skip_message="Does not support SHA1",
)
@@ -48,7 +48,7 @@ class TestSHA224(object):
hashes.SHA224,
digest_size=28,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.SHA224),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA224),
skip_message="Does not support SHA224",
)
@@ -58,7 +58,7 @@ class TestSHA256(object):
hashes.SHA256,
digest_size=32,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.SHA256),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA256),
skip_message="Does not support SHA256",
)
@@ -68,7 +68,7 @@ class TestSHA384(object):
hashes.SHA384,
digest_size=48,
block_size=128,
- only_if=lambda api: api.supports_hash(hashes.SHA384),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA384),
skip_message="Does not support SHA384",
)
@@ -78,7 +78,7 @@ class TestSHA512(object):
hashes.SHA512,
digest_size=64,
block_size=128,
- only_if=lambda api: api.supports_hash(hashes.SHA512),
+ only_if=lambda backend: backend.supports_hash(hashes.SHA512),
skip_message="Does not support SHA512",
)
@@ -88,7 +88,7 @@ class TestRIPEMD160(object):
hashes.RIPEMD160,
digest_size=20,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.RIPEMD160),
+ only_if=lambda backend: backend.supports_hash(hashes.RIPEMD160),
skip_message="Does not support RIPEMD160",
)
@@ -98,7 +98,7 @@ class TestWhirlpool(object):
hashes.Whirlpool,
digest_size=64,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.Whirlpool),
+ only_if=lambda backend: backend.supports_hash(hashes.Whirlpool),
skip_message="Does not support Whirlpool",
)
@@ -108,6 +108,6 @@ class TestMD5(object):
hashes.MD5,
digest_size=16,
block_size=64,
- only_if=lambda api: api.supports_hash(hashes.MD5),
+ only_if=lambda backend: backend.supports_hash(hashes.MD5),
skip_message="Does not support MD5",
)
diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py
index 86ff7cad..ff42b169 100644
--- a/tests/primitives/test_openssl_vectors.py
+++ b/tests/primitives/test_openssl_vectors.py
@@ -32,7 +32,7 @@ class TestCamelliaCBC(object):
["camellia-cbc.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.CBC(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher(
+ only_if=lambda backend: backend.supports_cipher(
ciphers.Camellia("\x00" * 16), modes.CBC("\x00" * 16)
),
skip_message="Does not support Camellia CBC",
@@ -46,7 +46,7 @@ class TestCamelliaOFB(object):
["camellia-ofb.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.OFB(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher(
+ only_if=lambda backend: backend.supports_cipher(
ciphers.Camellia("\x00" * 16), modes.OFB("\x00" * 16)
),
skip_message="Does not support Camellia OFB",
@@ -60,7 +60,7 @@ class TestCamelliaCFB(object):
["camellia-cfb.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.CFB(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher(
+ only_if=lambda backend: backend.supports_cipher(
ciphers.Camellia("\x00" * 16), modes.CFB("\x00" * 16)
),
skip_message="Does not support Camellia CFB",
@@ -74,7 +74,7 @@ class TestAESCTR(object):
["aes-128-ctr.txt", "aes-192-ctr.txt", "aes-256-ctr.txt"],
lambda key, iv: ciphers.AES(binascii.unhexlify(key)),
lambda key, iv: modes.CTR(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher(
+ only_if=lambda backend: backend.supports_cipher(
ciphers.AES("\x00" * 16), modes.CTR("\x00" * 16)
),
skip_message="Does not support AES CTR",
diff --git a/tests/primitives/test_utils.py b/tests/primitives/test_utils.py
index 6e197923..b7fa3d35 100644
--- a/tests/primitives/test_utils.py
+++ b/tests/primitives/test_utils.py
@@ -10,7 +10,7 @@ class TestEncryptTest(object):
with pytest.raises(pytest.skip.Exception) as exc_info:
encrypt_test(
None, None, None, None,
- only_if=lambda api: False,
+ only_if=lambda backend: False,
skip_message="message!"
)
assert exc_info.value.args[0] == "message!"
@@ -21,7 +21,7 @@ class TestHashTest(object):
with pytest.raises(pytest.skip.Exception) as exc_info:
hash_test(
None, None, None,
- only_if=lambda api: False,
+ only_if=lambda backend: False,
skip_message="message!"
)
assert exc_info.value.args[0] == "message!"
@@ -32,7 +32,7 @@ class TestBaseHashTest(object):
with pytest.raises(pytest.skip.Exception) as exc_info:
base_hash_test(
None, None, None, None,
- only_if=lambda api: False,
+ only_if=lambda backend: False,
skip_message="message!"
)
assert exc_info.value.args[0] == "message!"
@@ -43,7 +43,7 @@ class TestLongHashTest(object):
with pytest.raises(pytest.skip.Exception) as exc_info:
long_string_hash_test(
None, None, None,
- only_if=lambda api: False,
+ only_if=lambda backend: False,
skip_message="message!"
)
assert exc_info.value.args[0] == "message!"
diff --git a/tests/primitives/utils.py b/tests/primitives/utils.py
index 91ca36d8..d3b2134f 100644
--- a/tests/primitives/utils.py
+++ b/tests/primitives/utils.py
@@ -3,20 +3,20 @@ import os
import pytest
-from cryptography.bindings import _ALL_APIS
+from cryptography.bindings import _ALL_BACKENDS
from cryptography.primitives.block import BlockCipher
def generate_encrypt_test(param_loader, path, file_names, cipher_factory,
- mode_factory, only_if=lambda api: True,
+ mode_factory, only_if=lambda backend: True,
skip_message=None):
def test_encryption(self):
- for api in _ALL_APIS:
+ for backend in _ALL_BACKENDS:
for file_name in file_names:
for params in param_loader(os.path.join(path, file_name)):
yield (
encrypt_test,
- api,
+ backend,
cipher_factory,
mode_factory,
params,
@@ -26,16 +26,16 @@ def generate_encrypt_test(param_loader, path, file_names, cipher_factory,
return test_encryption
-def encrypt_test(api, cipher_factory, mode_factory, params, only_if,
+def encrypt_test(backend, cipher_factory, mode_factory, params, only_if,
skip_message):
- if not only_if(api):
+ if not only_if(backend):
pytest.skip(skip_message)
plaintext = params.pop("plaintext")
ciphertext = params.pop("ciphertext")
cipher = BlockCipher(
cipher_factory(**params),
mode_factory(**params),
- api
+ backend
)
encryptor = cipher.encryptor()
actual_ciphertext = encryptor.update(binascii.unhexlify(plaintext))
@@ -50,12 +50,12 @@ def encrypt_test(api, cipher_factory, mode_factory, params, only_if,
def generate_hash_test(param_loader, path, file_names, hash_cls,
only_if=None, skip_message=None):
def test_hash(self):
- for api in _ALL_APIS:
+ for backend in _ALL_BACKENDS:
for file_name in file_names:
for params in param_loader(os.path.join(path, file_name)):
yield (
hash_test,
- api,
+ backend,
hash_cls,
params,
only_if,
@@ -64,25 +64,25 @@ def generate_hash_test(param_loader, path, file_names, hash_cls,
return test_hash
-def hash_test(api, hash_cls, params, only_if, skip_message):
- if only_if is not None and not only_if(api):
+def hash_test(backend, hash_cls, params, only_if, skip_message):
+ if only_if is not None and not only_if(backend):
pytest.skip(skip_message)
msg = params[0]
md = params[1]
- m = hash_cls(api=api)
+ m = hash_cls(backend=backend)
m.update(binascii.unhexlify(msg))
assert m.hexdigest() == md.replace(" ", "").lower()
- digest = hash_cls(api=api, data=binascii.unhexlify(msg)).hexdigest()
- assert digest == md.replace(" ", "").lower()
+ digst = hash_cls(backend=backend, data=binascii.unhexlify(msg)).hexdigest()
+ assert digst == md.replace(" ", "").lower()
def generate_base_hash_test(hash_cls, digest_size, block_size,
only_if=None, skip_message=None):
def test_base_hash(self):
- for api in _ALL_APIS:
+ for backend in _ALL_BACKENDS:
yield (
base_hash_test,
- api,
+ backend,
hash_cls,
digest_size,
block_size,
@@ -92,11 +92,11 @@ def generate_base_hash_test(hash_cls, digest_size, block_size,
return test_base_hash
-def base_hash_test(api, hash_cls, digest_size, block_size, only_if,
+def base_hash_test(backend, hash_cls, digest_size, block_size, only_if,
skip_message):
- if only_if is not None and not only_if(api):
+ if only_if is not None and not only_if(backend):
pytest.skip(skip_message)
- m = hash_cls(api=api)
+ m = hash_cls(backend=backend)
assert m.digest_size == digest_size
assert m.block_size == block_size
m_copy = m.copy()
@@ -107,10 +107,10 @@ def base_hash_test(api, hash_cls, digest_size, block_size, only_if,
def generate_long_string_hash_test(hash_factory, md, only_if=None,
skip_message=None):
def test_long_string_hash(self):
- for api in _ALL_APIS:
+ for backend in _ALL_BACKENDS:
yield(
long_string_hash_test,
- api,
+ backend,
hash_factory,
md,
only_if,
@@ -119,9 +119,9 @@ def generate_long_string_hash_test(hash_factory, md, only_if=None,
return test_long_string_hash
-def long_string_hash_test(api, hash_factory, md, only_if, skip_message):
- if only_if is not None and not only_if(api):
+def long_string_hash_test(backend, hash_factory, md, only_if, skip_message):
+ if only_if is not None and not only_if(backend):
pytest.skip(skip_message)
- m = hash_factory(api=api)
+ m = hash_factory(backend=backend)
m.update(b"a" * 1000000)
assert m.hexdigest() == md.lower()