diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-09-10 18:54:13 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-09-10 19:47:50 -0500 |
commit | c024255dda87decd65bd05bd767feda0b43f80c7 (patch) | |
tree | 31d0be418c0d65405a14d6ded68d15c50f9dcb73 | |
parent | 5266752c9e462ac988af3d222470a68b2950d2d6 (diff) | |
download | cryptography-c024255dda87decd65bd05bd767feda0b43f80c7.tar.gz cryptography-c024255dda87decd65bd05bd767feda0b43f80c7.tar.bz2 cryptography-c024255dda87decd65bd05bd767feda0b43f80c7.zip |
move abc, inline introspect method, use six for abcs
* abc moved to cryptography.primitive.interfaces
* six added to dependencies
* six used to have py2x/py3x compatible abc
* nonce abc removed for now
-rw-r--r-- | cryptography/bindings/openssl/api.py | 18 | ||||
-rw-r--r-- | cryptography/primitives/abc/__init__.py | 0 | ||||
-rw-r--r-- | cryptography/primitives/abc/block/__init__.py | 0 | ||||
-rw-r--r-- | cryptography/primitives/block/modes.py | 4 | ||||
-rw-r--r-- | cryptography/primitives/interfaces.py (renamed from cryptography/primitives/abc/block/modes.py) | 6 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tox.ini | 1 |
7 files changed, 14 insertions, 17 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index f95e4d62..917c1846 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -13,7 +13,7 @@ from __future__ import absolute_import, division, print_function -from cryptography.primitives.abc.block import modes +from cryptography.primitives import interfaces import cffi @@ -74,12 +74,14 @@ class API(object): ) evp_cipher = self._lib.EVP_get_cipherbyname(ciphername.encode("ascii")) assert evp_cipher != self._ffi.NULL - iv_nonce = self._introspect(mode) + if isinstance(mode, interfaces.ModeWithInitializationVector): + iv_nonce = mode.initialization_vector + else: + iv_nonce = self._ffi.NULL # TODO: Sometimes this needs to be a DecryptInit, when? res = self._lib.EVP_EncryptInit_ex( - ctx, evp_cipher, self._ffi.NULL, cipher.key, - iv_nonce + ctx, evp_cipher, self._ffi.NULL, cipher.key, iv_nonce ) assert res != 0 @@ -88,14 +90,6 @@ class API(object): self._lib.EVP_CIPHER_CTX_set_padding(ctx, 0) return ctx - def _introspect(self, mode): - if isinstance(mode, modes.ModeWithInitializationVector): - return mode.initialization_vector - elif isinstance(mode, modes.ModeWithNonce): - return mode.nonce - else: - return self._ffi.NULL - def update_encrypt_context(self, ctx, plaintext): buf = self._ffi.new("unsigned char[]", len(plaintext)) outlen = self._ffi.new("int *") diff --git a/cryptography/primitives/abc/__init__.py b/cryptography/primitives/abc/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/cryptography/primitives/abc/__init__.py +++ /dev/null diff --git a/cryptography/primitives/abc/block/__init__.py b/cryptography/primitives/abc/block/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/cryptography/primitives/abc/block/__init__.py +++ /dev/null diff --git a/cryptography/primitives/block/modes.py b/cryptography/primitives/block/modes.py index 1e9b14b7..c722e739 100644 --- a/cryptography/primitives/block/modes.py +++ b/cryptography/primitives/block/modes.py @@ -13,7 +13,7 @@ from __future__ import absolute_import, division, print_function -from cryptography.primitives.abc.block import modes +from cryptography.primitives import interfaces class CBC(object): @@ -28,4 +28,4 @@ class ECB(object): name = "ECB" -modes.ModeWithInitializationVector.register(CBC) +interfaces.ModeWithInitializationVector.register(CBC) diff --git a/cryptography/primitives/abc/block/modes.py b/cryptography/primitives/interfaces.py index 609a2ae3..a2b091df 100644 --- a/cryptography/primitives/abc/block/modes.py +++ b/cryptography/primitives/interfaces.py @@ -14,8 +14,8 @@ from __future__ import absolute_import, division, print_function import abc +import six -ModeWithInitializationVector = abc.ABCMeta('ModeWithInitializationVector', - (object, ), {}) -ModeWithNonce = abc.ABCMeta('ModeWithNonce', (object, ), {}) +class ModeWithInitializationVector(six.with_metaclass(abc.ABCMeta)): + pass @@ -21,9 +21,11 @@ with open("cryptography/__about__.py") as fp: CFFI_DEPENDENCY = "cffi>=0.6" +SIX_DEPENDENCY = "six>=1.4.1" install_requires = [ CFFI_DEPENDENCY, + SIX_DEPENDENCY ] setup_requires = [ @@ -5,6 +5,7 @@ envlist = py26,py27,pypy,py32,py33,docs,pep8 deps = pytest-cov pretend + six commands = py.test --cov=cryptography/ --cov=tests/ [testenv:docs] |