From 39a45c5741ea5c62af2fd530d8fb3ebc2055116a Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Fri, 13 Sep 2013 20:58:09 -0500 Subject: Various PR review fixes * Changed some single quotes to double quotes * Moved the files in the cffi package back into the openssl package * evp, opensslv * Changed attrs from ALL CAPS * Fixed up docstrings * Stopped using fromlist=['*'] * No fallback on definition imports. You must supply includes, types, functions * Change includes, types, functions to be strings rather than lists for now * Removed teardown since we're not using it right now --- cryptography/bindings/openssl/api.py | 39 +++++++++++++------------- cryptography/bindings/openssl/cffi/__init__.py | 0 cryptography/bindings/openssl/cffi/evp.py | 39 -------------------------- cryptography/bindings/openssl/cffi/opensslv.py | 23 --------------- cryptography/bindings/openssl/evp.py | 36 ++++++++++++++++++++++++ cryptography/bindings/openssl/opensslv.py | 23 +++++++++++++++ 6 files changed, 78 insertions(+), 82 deletions(-) delete mode 100644 cryptography/bindings/openssl/cffi/__init__.py delete mode 100644 cryptography/bindings/openssl/cffi/evp.py delete mode 100644 cryptography/bindings/openssl/cffi/opensslv.py create mode 100644 cryptography/bindings/openssl/evp.py create mode 100644 cryptography/bindings/openssl/opensslv.py diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index f2369406..c5da9fb1 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -16,22 +16,21 @@ from __future__ import absolute_import, division, print_function from cryptography.primitives import interfaces import cffi +import sys class API(object): """ OpenSSL API wrapper. """ - # TODO: is there a way to enumerate the files in the cffi module - # rather than hardcode them? _modules = [ - 'evp', - 'opensslv', + "evp", + "opensslv", ] def __init__(self): self._ffi = cffi.FFI() - self.INCLUDES, self.TYPES, self.FUNCTIONS = [], [], [] + self.includes, self.types, self.functions = [], [], [] self._import() self._define() self._verify() @@ -39,32 +38,32 @@ class API(object): self._lib.OpenSSL_add_all_algorithms() def _import(self): - "import all library definitions" + """ + Import all library definitions + """ for name in self._modules: - module = __import__('cryptography.bindings.openssl.cffi.' + name, - fromlist=['*']) - self._import_definitions(module, 'INCLUDES') - self._import_definitions(module, 'TYPES') - self._import_definitions(module, 'FUNCTIONS') + __import__('cryptography.bindings.openssl.' + name) + module = sys.modules['cryptography.bindings.openssl.' + name] + self._import_definitions(module, 'includes') + self._import_definitions(module, 'types') + self._import_definitions(module, 'functions') def _import_definitions(self, module, name): - "import defintions named definitions from module" + """ + Import definitions named definitions from module + """ container = getattr(self, name) - for definition in getattr(module, name, ()): - if definition not in container: - container.append(definition) + container.append(getattr(module, name)) def _define(self): - "parse function definitions" - for typedef in self.TYPES: + for typedef in self.types: self._ffi.cdef(typedef) - for function in self.FUNCTIONS: + for function in self.functions: self._ffi.cdef(function) def _verify(self): - "load openssl, create function attributes" self._lib = self._ffi.verify( - source="\n".join(self.INCLUDES), + source="\n".join(self.includes), libraries=['crypto'] ) diff --git a/cryptography/bindings/openssl/cffi/__init__.py b/cryptography/bindings/openssl/cffi/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/cryptography/bindings/openssl/cffi/evp.py b/cryptography/bindings/openssl/cffi/evp.py deleted file mode 100644 index be72a265..00000000 --- a/cryptography/bindings/openssl/cffi/evp.py +++ /dev/null @@ -1,39 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -INCLUDES = [ - "#include " -] - -TEARDOWN = [ -] - -TYPES = [ - "typedef struct { ...; } EVP_CIPHER_CTX;", - "typedef ... EVP_CIPHER;", - "typedef ... ENGINE;", -] - -FUNCTIONS = [ - "void OpenSSL_add_all_algorithms();", - "const EVP_CIPHER *EVP_get_cipherbyname(const char *);", - "int EVP_EncryptInit_ex(EVP_CIPHER_CTX *, const EVP_CIPHER *, \ - ENGINE *, unsigned char *, unsigned char *);", - "int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int);", - "int EVP_EncryptUpdate(EVP_CIPHER_CTX *, unsigned char *, int *, \ - unsigned char *, int);", - "int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *, unsigned char *, int *);", - "int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);", - "const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *);", - "int EVP_CIPHER_block_size(const EVP_CIPHER *);", -] diff --git a/cryptography/bindings/openssl/cffi/opensslv.py b/cryptography/bindings/openssl/cffi/opensslv.py deleted file mode 100644 index 33212b89..00000000 --- a/cryptography/bindings/openssl/cffi/opensslv.py +++ /dev/null @@ -1,23 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -INCLUDES = [ - "#include " -] - -TYPES = [ - "static char *const OPENSSL_VERSION_TEXT;" -] - -FUNCTIONS = [ -] diff --git a/cryptography/bindings/openssl/evp.py b/cryptography/bindings/openssl/evp.py new file mode 100644 index 00000000..0d969cf8 --- /dev/null +++ b/cryptography/bindings/openssl/evp.py @@ -0,0 +1,36 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +includes = """ + #include +""" + +types = """ + typedef struct { ...; } EVP_CIPHER_CTX; + typedef ... EVP_CIPHER; + typedef ... ENGINE; +""" + +functions = """ + void OpenSSL_add_all_algorithms(); + const EVP_CIPHER *EVP_get_cipherbyname(const char *); + int EVP_EncryptInit_ex(EVP_CIPHER_CTX *, const EVP_CIPHER *, + ENGINE *, unsigned char *, unsigned char *); + int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int); + int EVP_EncryptUpdate(EVP_CIPHER_CTX *, unsigned char *, int *, + unsigned char *, int); + int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *, unsigned char *, int *); + int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); + const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *); + int EVP_CIPHER_block_size(const EVP_CIPHER *); +""" diff --git a/cryptography/bindings/openssl/opensslv.py b/cryptography/bindings/openssl/opensslv.py new file mode 100644 index 00000000..ace7bded --- /dev/null +++ b/cryptography/bindings/openssl/opensslv.py @@ -0,0 +1,23 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +includes = """ + #include +""" + +types = """ + static char *const OPENSSL_VERSION_TEXT; +""" + + +functions = "" -- cgit v1.2.3