Use a None default so composition is easier
diff --git a/cryptography/primitives/block/base.py b/cryptography/primitives/block/base.py
index 197807e..b84ca9c 100644
--- a/cryptography/primitives/block/base.py
+++ b/cryptography/primitives/block/base.py
@@ -24,8 +24,12 @@
class BlockCipher(object):
- def __init__(self, cipher, mode, api=_default_api):
+ def __init__(self, cipher, mode, api=None):
super(BlockCipher, self).__init__()
+
+ if api is None:
+ api = _default_api
+
self.cipher = cipher
self.mode = mode
self._api = api
diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py
index 92fd31a..774885f 100644
--- a/tests/primitives/test_block.py
+++ b/tests/primitives/test_block.py
@@ -31,6 +31,13 @@
)
assert cipher.name == "AES-128-CBC"
+ def test_instantiate_without_api(self):
+ cipher = BlockCipher(
+ ciphers.AES(binascii.unhexlify(b"0" * 32)),
+ modes.CBC(binascii.unhexlify(b"0" * 32))
+ )
+ assert cipher.name == "AES-128-CBC"
+
def test_use_after_finalize(self, api):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(b"0" * 32)),
diff --git a/tox.ini b/tox.ini
index 88e7421..0a28af1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,7 +8,7 @@
pretend
commands =
coverage run --source=cryptography/,tests/ -m pytest
- coverage report
+ coverage report -m
[testenv:docs]
deps = sphinx