aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2013-09-13 20:58:09 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2013-09-13 20:58:09 -0500
commit39a45c5741ea5c62af2fd530d8fb3ebc2055116a (patch)
tree4b608c7012b966fd3fc2b798d5eca4e525a659cf
parent51c65b9a0b31740a5f87e8ef74f8a103d583e8ee (diff)
downloadcryptography-39a45c5741ea5c62af2fd530d8fb3ebc2055116a.tar.gz
cryptography-39a45c5741ea5c62af2fd530d8fb3ebc2055116a.tar.bz2
cryptography-39a45c5741ea5c62af2fd530d8fb3ebc2055116a.zip
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
-rw-r--r--cryptography/bindings/openssl/api.py39
-rw-r--r--cryptography/bindings/openssl/cffi/__init__.py0
-rw-r--r--cryptography/bindings/openssl/cffi/evp.py39
-rw-r--r--cryptography/bindings/openssl/evp.py36
-rw-r--r--cryptography/bindings/openssl/opensslv.py (renamed from cryptography/bindings/openssl/cffi/opensslv.py)16
5 files changed, 63 insertions, 67 deletions
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
--- a/cryptography/bindings/openssl/cffi/__init__.py
+++ /dev/null
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 <openssl/evp.h>"
-]
-
-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/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 <openssl/evp.h>
+"""
+
+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/opensslv.py
index 33212b89..ace7bded 100644
--- a/cryptography/bindings/openssl/cffi/opensslv.py
+++ b/cryptography/bindings/openssl/opensslv.py
@@ -11,13 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-INCLUDES = [
- "#include <openssl/opensslv.h>"
-]
+includes = """
+ #include <openssl/opensslv.h>
+"""
-TYPES = [
- "static char *const OPENSSL_VERSION_TEXT;"
-]
+types = """
+ static char *const OPENSSL_VERSION_TEXT;
+"""
-FUNCTIONS = [
-]
+
+functions = ""