Merge pull request #48 from reaperhulk/master
Add OpenSSL Version Text Method
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index 202595b..54a74d0 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -27,6 +27,7 @@
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 @@
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 @@
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 2e47870..cf54aa3 100644
--- a/cryptography/primitives/block/ciphers.py
+++ b/cryptography/primitives/block/ciphers.py
@@ -25,7 +25,7 @@
# 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 9d63722..1579f00 100644
--- a/tests/bindings/test_openssl.py
+++ b/tests/bindings/test_openssl.py
@@ -17,3 +17,14 @@
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")