diff options
Diffstat (limited to 'OpenSSL/_util.py')
-rw-r--r-- | OpenSSL/_util.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/OpenSSL/_util.py b/OpenSSL/_util.py index baeecc6..cf13666 100644 --- a/OpenSSL/_util.py +++ b/OpenSSL/_util.py @@ -5,11 +5,25 @@ binding = Binding() ffi = binding.ffi lib = binding.lib -def exception_from_error_queue(exceptionType): - def text(charp): - return native(ffi.string(charp)) + + +def text(charp): + return native(ffi.string(charp)) + + + +def exception_from_error_queue(exception_type): + """ + Convert an OpenSSL library failure into a Python exception. + + When a call to the native OpenSSL library fails, this is usually signalled + by the return value, and an error code is stored in an error queue + associated with the current thread. The err library provides functions to + obtain these error codes and textual error messages. + """ errors = [] + while True: error = lib.ERR_get_error() if error == 0: @@ -19,7 +33,7 @@ def exception_from_error_queue(exceptionType): text(lib.ERR_func_error_string(error)), text(lib.ERR_reason_error_string(error)))) - raise exceptionType(errors) + raise exception_type(errors) |