diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2015-03-15 16:32:13 -0400 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2015-03-15 16:32:13 -0400 |
commit | 15111f26d4594a078a017e7fee5b92651c77b2b5 (patch) | |
tree | ed474b4d39bc0ed87cfc40a33861b8427db0c578 /OpenSSL/_util.py | |
parent | 85ce662560419a34cf0fbfb60836e1602a693586 (diff) | |
parent | 876b2ac5929fd9edcf7c03d1f28ee5334bce60ea (diff) | |
download | pyopenssl-remove-rationale.tar.gz |
merge masterremove-rationale
Diffstat (limited to 'OpenSSL/_util.py')
-rw-r--r-- | OpenSSL/_util.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/OpenSSL/_util.py b/OpenSSL/_util.py index baeecc6..de292be 100644 --- a/OpenSSL/_util.py +++ b/OpenSSL/_util.py @@ -5,11 +5,32 @@ 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): + """ + Get a native string type representing of the given CFFI ``char*`` object. + + :param charp: A C-style string represented using CFFI. + + :return: :class:`str` + """ + 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 +40,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) |