aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-09-09 15:56:05 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-09-09 15:56:05 -0700
commit6fc8cee0d7b851fde2d0065ee2cea603ba4cfd53 (patch)
tree8ae3f83bc0b6cdb78f8a4c681f2744ab028ee6c7
parent5e00e96f20f8c70614b463015e64a277a4348576 (diff)
parentc1a218d3b9d8ca02851df3b8eebb4685bd35776f (diff)
downloadcryptography-6fc8cee0d7b851fde2d0065ee2cea603ba4cfd53.tar.gz
cryptography-6fc8cee0d7b851fde2d0065ee2cea603ba4cfd53.tar.bz2
cryptography-6fc8cee0d7b851fde2d0065ee2cea603ba4cfd53.zip
Merge pull request #48 from reaperhulk/master
Add OpenSSL Version Text Method
-rw-r--r--cryptography/bindings/openssl/api.py11
-rw-r--r--cryptography/primitives/block/ciphers.py2
-rw-r--r--tests/bindings/test_openssl.py11
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")