aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-22 19:24:31 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-22 19:24:31 -0700
commit25c0037d0d1bf4b4d426cc03b9390456d127d4d7 (patch)
treefebc087d21873d764c7701a18f79cf4eef649f9c
parent68e5de708d623a03ea4cbd4d3a4297b5722950eb (diff)
parentf4c59767cdfe7716c82a72b00baa427637b505bd (diff)
downloadcryptography-25c0037d0d1bf4b4d426cc03b9390456d127d4d7.tar.gz
cryptography-25c0037d0d1bf4b4d426cc03b9390456d127d4d7.tar.bz2
cryptography-25c0037d0d1bf4b4d426cc03b9390456d127d4d7.zip
Merge pull request #172 from reaperhulk/api-to-backend-in-one-easy-step
The great api -> backend rename
-rw-r--r--cryptography/bindings/__init__.py6
-rw-r--r--cryptography/bindings/openssl/__init__.py4
-rw-r--r--cryptography/bindings/openssl/backend.py (renamed from cryptography/bindings/openssl/api.py)12
-rw-r--r--cryptography/primitives/block/base.py36
-rw-r--r--cryptography/primitives/hashes.py27
-rw-r--r--docs/bindings/openssl.rst2
-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.py40
-rw-r--r--tests/primitives/test_openssl_vectors.py8
-rw-r--r--tests/primitives/test_utils.py8
-rw-r--r--tests/primitives/utils.py48
15 files changed, 124 insertions, 117 deletions
diff --git a/cryptography/bindings/__init__.py b/cryptography/bindings/__init__.py
index 215f17c7..5006d134 100644
--- a/cryptography/bindings/__init__.py
+++ b/cryptography/bindings/__init__.py
@@ -14,7 +14,7 @@
from cryptography.bindings import openssl
-_default_api = openssl.api
-_ALL_APIS = [
- openssl.api
+_default_backend = openssl.backend
+_ALL_BACKENDS = [
+ openssl.backend
]
diff --git a/cryptography/bindings/openssl/__init__.py b/cryptography/bindings/openssl/__init__.py
index 103b1db0..cfe2e665 100644
--- a/cryptography/bindings/openssl/__init__.py
+++ b/cryptography/bindings/openssl/__init__.py
@@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from cryptography.bindings.openssl.api import api
+from cryptography.bindings.openssl.backend import backend
-__all__ = ["api"]
+__all__ = ["backend"]
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/backend.py
index fedaf9cc..492f2e54 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/backend.py
@@ -27,12 +27,12 @@ class GetCipherByName(object):
def __init__(self, fmt):
self._fmt = fmt
- def __call__(self, api, cipher, mode):
+ def __call__(self, backend, cipher, mode):
cipher_name = self._fmt.format(cipher=cipher, mode=mode).lower()
- return api.lib.EVP_get_cipherbyname(cipher_name.encode("ascii"))
+ return backend.lib.EVP_get_cipherbyname(cipher_name.encode("ascii"))
-class API(object):
+class Backend(object):
"""
OpenSSL API wrapper.
"""
@@ -144,7 +144,7 @@ class API(object):
def create_block_cipher_encrypt_context(self, cipher, mode):
ctx, evp, iv_nonce = self._create_block_cipher_context(cipher, mode)
- res = self.lib.EVP_EncryptInit_ex(ctx, evp, api.ffi.NULL, cipher.key,
+ res = self.lib.EVP_EncryptInit_ex(ctx, evp, self.ffi.NULL, cipher.key,
iv_nonce)
assert res != 0
# We purposely disable padding here as it's handled higher up in the
@@ -154,7 +154,7 @@ class API(object):
def create_block_cipher_decrypt_context(self, cipher, mode):
ctx, evp, iv_nonce = self._create_block_cipher_context(cipher, mode)
- res = self.lib.EVP_DecryptInit_ex(ctx, evp, api.ffi.NULL, cipher.key,
+ res = self.lib.EVP_DecryptInit_ex(ctx, evp, self.ffi.NULL, cipher.key,
iv_nonce)
assert res != 0
# We purposely disable padding here as it's handled higher up in the
@@ -247,4 +247,4 @@ class API(object):
return copied_ctx
-api = API()
+backend = Backend()
diff --git a/cryptography/primitives/block/base.py b/cryptography/primitives/block/base.py
index 12b6f626..e9f52887 100644
--- a/cryptography/primitives/block/base.py
+++ b/cryptography/primitives/block/base.py
@@ -17,58 +17,62 @@ from cryptography.primitives import interfaces
class BlockCipher(object):
- def __init__(self, cipher, mode, api=None):
+ def __init__(self, cipher, mode, backend=None):
super(BlockCipher, self).__init__()
- if api is None:
- from cryptography.bindings import _default_api as api
+ if backend is None:
+ from cryptography.bindings import _default_backend as backend
self.cipher = cipher
self.mode = mode
- self._api = api
+ self._backend = backend
def encryptor(self):
- return _CipherEncryptionContext(self.cipher, self.mode, self._api)
+ return _CipherEncryptionContext(self.cipher, self.mode, self._backend)
def decryptor(self):
- return _CipherDecryptionContext(self.cipher, self.mode, self._api)
+ return _CipherDecryptionContext(self.cipher, self.mode, self._backend)
@interfaces.register(interfaces.CipherContext)
class _CipherEncryptionContext(object):
- def __init__(self, cipher, mode, api):
+ def __init__(self, cipher, mode, backend):
super(_CipherEncryptionContext, self).__init__()
- self._api = api
- self._ctx = self._api.create_block_cipher_encrypt_context(cipher, mode)
+ self._backend = backend
+ self._ctx = self._backend.create_block_cipher_encrypt_context(
+ cipher, mode
+ )
def update(self, data):
if self._ctx is None:
raise ValueError("Context was already finalized")
- return self._api.update_encrypt_context(self._ctx, data)
+ return self._backend.update_encrypt_context(self._ctx, data)
def finalize(self):
if self._ctx is None:
raise ValueError("Context was already finalized")
- data = self._api.finalize_encrypt_context(self._ctx)
+ data = self._backend.finalize_encrypt_context(self._ctx)
self._ctx = None
return data
@interfaces.register(interfaces.CipherContext)
class _CipherDecryptionContext(object):
- def __init__(self, cipher, mode, api):
+ def __init__(self, cipher, mode, backend):
super(_CipherDecryptionContext, self).__init__()
- self._api = api
- self._ctx = self._api.create_block_cipher_decrypt_context(cipher, mode)
+ self._backend = backend
+ self._ctx = self._backend.create_block_cipher_decrypt_context(
+ cipher, mode
+ )
def update(self, data):
if self._ctx is None:
raise ValueError("Context was already finalized")
- return self._api.update_decrypt_context(self._ctx, data)
+ return self._backend.update_decrypt_context(self._ctx, data)
def finalize(self):
if self._ctx is None:
raise ValueError("Context was already finalized")
- data = self._api.finalize_decrypt_context(self._ctx)
+ data = self._backend.finalize_decrypt_context(self._ctx)
self._ctx = None
return data
diff --git a/cryptography/primitives/hashes.py b/cryptography/primitives/hashes.py
index 3aa52462..4cd68adc 100644
--- a/cryptography/primitives/hashes.py
+++ b/cryptography/primitives/hashes.py
@@ -19,35 +19,38 @@ import binascii
import six
-from cryptography.bindings import _default_api
-
class BaseHash(six.with_metaclass(abc.ABCMeta)):
- def __init__(self, data=None, api=None, ctx=None):
- if api is None:
- api = _default_api
- self._api = api
- self._ctx = self._api.create_hash_context(self) if ctx is None else ctx
+ def __init__(self, data=None, backend=None, ctx=None):
+ if backend is None:
+ from cryptography.bindings import _default_backend
+ backend = _default_backend
+ self._backend = backend
+ if ctx is None:
+ self._ctx = self._backend.create_hash_context(self)
+ else:
+ self._ctx = None
+
if data is not None:
self.update(data)
def update(self, data):
if isinstance(data, six.text_type):
raise TypeError("Unicode-objects must be encoded before hashing")
- self._api.update_hash_context(self._ctx, data)
+ self._backend.update_hash_context(self._ctx, data)
def copy(self):
- return self.__class__(api=self._api, ctx=self._copy_ctx())
+ return self.__class__(backend=self._backend, ctx=self._copy_ctx())
def digest(self):
- return self._api.finalize_hash_context(self._copy_ctx(),
- self.digest_size)
+ return self._backend.finalize_hash_context(self._copy_ctx(),
+ self.digest_size)
def hexdigest(self):
return str(binascii.hexlify(self.digest()).decode("ascii"))
def _copy_ctx(self):
- return self._api.copy_hash_context(self._ctx)
+ return self._backend.copy_hash_context(self._ctx)
class SHA1(BaseHash):
diff --git a/docs/bindings/openssl.rst b/docs/bindings/openssl.rst
index 241cc4d6..e59b0c13 100644
--- a/docs/bindings/openssl.rst
+++ b/docs/bindings/openssl.rst
@@ -10,7 +10,7 @@ OpenSSL
These are `CFFI`_ bindings to the `OpenSSL`_ C library.
-.. data:: cryptography.bindings.openssl.api
+.. data:: cryptography.bindings.openssl.backend
This is the exposed API for the OpenSSL bindings. It has two public
attributes:
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 46517701..2efda050 100644
--- a/tests/primitives/test_hashes.py
+++ b/tests/primitives/test_hashes.py
@@ -19,7 +19,7 @@ import pytest
import six
-from cryptography.bindings import _default_api
+from cryptography.bindings import _default_backend
from cryptography.primitives import hashes
@@ -27,32 +27,32 @@ 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)
class TestCopyHash(object):
- def test_copy_api_object(self):
- pretend_api = pretend.stub(copy_hash_context=lambda a: "copiedctx")
+ def test_copy_backend_object(self):
+ pretend_backend = pretend.stub(copy_hash_context=lambda a: "copiedctx")
pretend_ctx = pretend.stub()
- h = hashes.SHA1(api=pretend_api, ctx=pretend_ctx)
- assert h._api is pretend_api
- assert h.copy()._api is h._api
+ h = hashes.SHA1(backend=pretend_backend, ctx=pretend_ctx)
+ assert h._backend is pretend_backend
+ assert h.copy()._backend is h._backend
class TestDefaultAPISHA1(object):
- def test_default_api_creation(self):
+ def test_default_backend_creation(self):
"""
This test assumes the presence of SHA1 in the default API.
"""
h = hashes.SHA1()
- assert h._api is _default_api
+ assert h._backend is _default_backend
class TestSHA1(object):
@@ -60,7 +60,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",
)
@@ -70,7 +70,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",
)
@@ -80,7 +80,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",
)
@@ -90,7 +90,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",
)
@@ -100,7 +100,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",
)
@@ -110,7 +110,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",
)
@@ -120,7 +120,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",
)
@@ -130,6 +130,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()