diff options
-rw-r--r-- | cryptography/bindings/openssl/api.py | 11 | ||||
-rw-r--r-- | cryptography/primitives/block/ciphers.py | 2 | ||||
-rw-r--r-- | tests/bindings/test_openssl.py | 11 |
3 files changed, 23 insertions, 1 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 202595bf..54a74d03 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 <openssl/evp.h> + #include <openssl/opensslv.h> """) 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,14 @@ class API(object): int EVP_CIPHER_block_size(const EVP_CIPHER *); """) + def openssl_version_text(self): + """ + Friendly string name of linked OpenSSL. + + Example: OpenSSL 1.0.1e 11 Feb 2013 + """ + return self._ffi.string(api._lib.OPENSSL_VERSION_TEXT).decode("ascii") + 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/cryptography/primitives/block/ciphers.py b/cryptography/primitives/block/ciphers.py index 2e478705..cf54aa35 100644 --- a/cryptography/primitives/block/ciphers.py +++ b/cryptography/primitives/block/ciphers.py @@ -25,7 +25,7 @@ class AES(object): # Verify that the key size matches the expected key size if self.key_size not in self.key_sizes: - raise ValueError("Invalid key size (%s) for %s".format( + raise ValueError("Invalid key size ({0}) for {1}".format( self.key_size, self.name )) diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index 9d637222..1579f002 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -17,3 +17,14 @@ from cryptography.bindings.openssl import api class TestOpenSSL(object): def test_api_exists(self): assert api + + def test_openssl_version_text(self): + """ + This test checks the value of OPENSSL_VERSION_TEXT. + + Unfortunately, this define does not appear to have a + formal content definition, so for now we'll test to see + if it starts with OpenSSL as that appears to be true + for every OpenSSL. + """ + assert api.openssl_version_text().startswith("OpenSSL") |