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
This commit is contained in:
Paul Kehrer 2013-09-10 18:54:13 -05:00
parent 5266752c9e
commit c024255dda
7 changed files with 14 additions and 17 deletions

View file

@ -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 *")

View file

@ -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)

View file

@ -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

View file

@ -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 = [

View file

@ -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]