From d55920576d288e9cb703337c6183cfe071d274ce Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 10:00:33 -0500 Subject: Fix issue mixing %s and format for ValueError in AES --- cryptography/primitives/block/ciphers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 )) -- cgit v1.2.3 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 From eb49db17f85c1a359e319df1a9adadcc8ee7236f Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 17:12:29 -0500 Subject: ascii decode on openssl_version_text + doc string improvements --- cryptography/bindings/openssl/api.py | 7 +++++-- tests/bindings/test_openssl.py | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 87ed38fa..2c8fae3d 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -55,9 +55,12 @@ 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) + """ Friendly string name of linked OpenSSL. + + Example: OpenSSL 1.0.1e Feb 11, 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 *") diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index 8704d933..db71e328 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -19,4 +19,11 @@ class TestOpenSSL(object): 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().find("OpenSSL") == 0 -- cgit v1.2.3 From 6c272f097b422ea2cd6b1ec2a3b3806c3296987d Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 17:31:47 -0500 Subject: Accurate friendly string name example text --- cryptography/bindings/openssl/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 2c8fae3d..fb68e21e 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -58,7 +58,7 @@ class API(object): def openssl_version_text(self): """ Friendly string name of linked OpenSSL. - Example: OpenSSL 1.0.1e Feb 11, 2013 + Example: OpenSSL 1.0.1e 11 Feb 2013 """ return self._ffi.string(api._lib.OPENSSL_VERSION_TEXT).decode("ascii") -- cgit v1.2.3 From bdafcd39172e118c4fc475770546ccef4d5e5784 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 17:44:11 -0500 Subject: openssl_version_text now calls startswith rather than find --- tests/bindings/test_openssl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index db71e328..e0baaf53 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -26,4 +26,4 @@ class TestOpenSSL(object): if it starts with OpenSSL as that appears to be true for every OpenSSL. """ - assert api.openssl_version_text().find("OpenSSL") == 0 + assert api.openssl_version_text().startswith("OpenSSL") -- cgit v1.2.3 From c1a218d3b9d8ca02851df3b8eebb4685bd35776f Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 9 Sep 2013 17:45:52 -0500 Subject: Update docstring to pass alex8 linting --- cryptography/bindings/openssl/api.py | 3 ++- tests/bindings/test_openssl.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index fb68e21e..54a74d03 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -56,7 +56,8 @@ class API(object): """) def openssl_version_text(self): - """ Friendly string name of linked OpenSSL. + """ + Friendly string name of linked OpenSSL. Example: OpenSSL 1.0.1e 11 Feb 2013 """ diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index e0baaf53..1579f002 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -19,7 +19,8 @@ class TestOpenSSL(object): assert api def test_openssl_version_text(self): - """ This test checks the value of OPENSSL_VERSION_TEXT. + """ + 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 -- cgit v1.2.3