aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/hazmat/bindings/openssl/binding.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2016-03-07 22:49:43 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2016-03-07 22:49:43 -0400
commitd76bd668dc4b59c037771ed5619f939d65ca9905 (patch)
tree41ab4fac4ba90fef0602255c62d05ee8877936db /src/cryptography/hazmat/bindings/openssl/binding.py
parent290272717c6d5fbdf074e72b9a444f7862c75f76 (diff)
downloadcryptography-d76bd668dc4b59c037771ed5619f939d65ca9905.tar.gz
cryptography-d76bd668dc4b59c037771ed5619f939d65ca9905.tar.bz2
cryptography-d76bd668dc4b59c037771ed5619f939d65ca9905.zip
only call ERR_error_string if we're going to raise InternalError
Diffstat (limited to 'src/cryptography/hazmat/bindings/openssl/binding.py')
-rw-r--r--src/cryptography/hazmat/bindings/openssl/binding.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/cryptography/hazmat/bindings/openssl/binding.py b/src/cryptography/hazmat/bindings/openssl/binding.py
index d8fd74db..47e64191 100644
--- a/src/cryptography/hazmat/bindings/openssl/binding.py
+++ b/src/cryptography/hazmat/bindings/openssl/binding.py
@@ -15,8 +15,10 @@ from cryptography.exceptions import InternalError
from cryptography.hazmat.bindings._openssl import ffi, lib
from cryptography.hazmat.bindings.openssl._conditional import CONDITIONAL_NAMES
-_OpenSSLError = collections.namedtuple(
- "_OpenSSLError", ["code", "lib", "func", "reason", "reason_text"]
+_OpenSSLError = collections.namedtuple("_OpenSSLError",
+ ["code", "lib", "func", "reason"])
+_OpenSSLErrorText = collections.namedtuple(
+ "_OpenSSLErrorText", ["code", "lib", "func", "reason", "reason_text"]
)
@@ -30,11 +32,8 @@ def _consume_errors(lib):
err_lib = lib.ERR_GET_LIB(code)
err_func = lib.ERR_GET_FUNC(code)
err_reason = lib.ERR_GET_REASON(code)
- err_text_reason = ffi.string(lib.ERR_error_string(code, ffi.NULL))
- errors.append(
- _OpenSSLError(code, err_lib, err_func, err_reason, err_text_reason)
- )
+ errors.append(_OpenSSLError(code, err_lib, err_func, err_reason))
return errors
@@ -42,15 +41,26 @@ def _consume_errors(lib):
def _openssl_assert(lib, ok):
if not ok:
errors = _consume_errors(lib)
+ errors_with_text = []
+ for err in errors:
+ err_text_reason = ffi.string(
+ lib.ERR_error_string(err.code, ffi.NULL)
+ )
+ errors_with_text.append(
+ _OpenSSLErrorText(
+ err.code, err.lib, err.func, err.reason, err_text_reason
+ )
+ )
+
raise InternalError(
"Unknown OpenSSL error. This error is commonly encountered when "
"another library is not cleaning up the OpenSSL error stack. If "
- "you are using cryptography with another Python library that "
- "uses OpenSSL try disabling it before reporting a bug. Otherwise "
- "iplease file an issue at https://github.com/pyca/cryptography/"
+ "you are using cryptography with another library that uses "
+ "OpenSSL try disabling it before reporting a bug. Otherwise "
+ "please file an issue at https://github.com/pyca/cryptography/"
"issues with information on how to reproduce "
- "this. ({0!r})".format(errors),
- errors
+ "this. ({0!r})".format(errors_with_text),
+ errors_with_text
)