From 733404a826678538f0b67d666d4c303b1ccc2204 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 15:26:26 -0500 Subject: Add method to bindings to get OPENSSL_VERSION_TEXT * This allows you to check that you're binding against the expected version of OpenSSL * Test is pretty basic (just checks to see that the string starts with OpenSSL) --- cryptography/bindings/openssl/api.py | 7 +++++++ tests/bindings/test_openssl.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 202595bf..87ed38fa 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -27,6 +27,7 @@ class API(object): self._ffi = ffi self._lib = ffi.verify(""" #include + #include """) self._lib.OpenSSL_add_all_algorithms() @@ -38,6 +39,8 @@ class API(object): typedef ... EVP_CIPHER; typedef ... ENGINE; + static char *const OPENSSL_VERSION_TEXT; + void OpenSSL_add_all_algorithms(); const EVP_CIPHER *EVP_get_cipherbyname(const char *); @@ -52,6 +55,10 @@ class API(object): int EVP_CIPHER_block_size(const EVP_CIPHER *); """) + """ Friendly string name of linked OpenSSL. """ + def openssl_version_text(self): + return self._ffi.string(api._lib.OPENSSL_VERSION_TEXT) + def create_block_cipher_context(self, cipher, mode): ctx = self._ffi.new("EVP_CIPHER_CTX *") ctx = self._ffi.gc(ctx, self._lib.EVP_CIPHER_CTX_cleanup) diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index 9d637222..8704d933 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -17,3 +17,6 @@ from cryptography.bindings.openssl import api class TestOpenSSL(object): def test_api_exists(self): assert api + + def test_openssl_version_text(self): + assert api.openssl_version_text().find("OpenSSL") == 0 -- cgit v1.2.3