diff options
author | Donald Stufft <donald@stufft.io> | 2013-10-02 10:51:48 -0700 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2013-10-02 10:51:48 -0700 |
commit | 640fb6ce669e8921efb31502512445144662021b (patch) | |
tree | db2d204092426b5ea724e4459e26510499e3f34d | |
parent | 538dd9ccab16edf23e7574f813933aaa4e29f30c (diff) | |
parent | 678149022b84ce275489afef4edf84a34a3074c1 (diff) | |
download | cryptography-640fb6ce669e8921efb31502512445144662021b.tar.gz cryptography-640fb6ce669e8921efb31502512445144662021b.tar.bz2 cryptography-640fb6ce669e8921efb31502512445144662021b.zip |
Merge pull request #78 from alex/check-cffi
Be stricter in type checking the C prototypes
-rw-r--r-- | cryptography/bindings/openssl/api.py | 16 | ||||
-rw-r--r-- | cryptography/bindings/openssl/evp.py | 7 | ||||
-rw-r--r-- | cryptography/bindings/openssl/opensslv.py | 3 |
3 files changed, 22 insertions, 4 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 28437576..cb5afe3f 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -32,16 +32,28 @@ class API(object): def __init__(self): self.ffi = cffi.FFI() includes = [] + functions = [] for name in self._modules: __import__("cryptography.bindings.openssl." + name) module = sys.modules["cryptography.bindings.openssl." + name] self.ffi.cdef(module.TYPES) self.ffi.cdef(module.FUNCTIONS) + self.ffi.cdef(module.MACROS) + + functions.append(module.FUNCTIONS) includes.append(module.INCLUDES) + # We include functions here so that if we got any of their definitions + # wrong, the underlying C compiler will explode. In C you are allowed + # to re-declare a function if it has the same signature. That is: + # int foo(int); + # int foo(int); + # is legal, but the following will fail to compile: + # int foo(int); + # int foo(short); self.lib = self.ffi.verify( - source="\n".join(includes), - libraries=["crypto"] + source="\n".join(includes + functions), + libraries=["crypto"], ) self.lib.OpenSSL_add_all_algorithms() diff --git a/cryptography/bindings/openssl/evp.py b/cryptography/bindings/openssl/evp.py index 0bc5cffc..8afaf342 100644 --- a/cryptography/bindings/openssl/evp.py +++ b/cryptography/bindings/openssl/evp.py @@ -27,13 +27,16 @@ 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 *); + const unsigned char *, const unsigned char *); int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int); int EVP_EncryptUpdate(EVP_CIPHER_CTX *, unsigned char *, int *, - unsigned char *, int); + const 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 *); void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *); """ + +MACROS = """ +""" diff --git a/cryptography/bindings/openssl/opensslv.py b/cryptography/bindings/openssl/opensslv.py index 9b2db270..d1a1b3e6 100644 --- a/cryptography/bindings/openssl/opensslv.py +++ b/cryptography/bindings/openssl/opensslv.py @@ -21,3 +21,6 @@ static char *const OPENSSL_VERSION_TEXT; FUNCTIONS = """ """ + +MACROS = """ +""" |