diff options
author | Jack Lloyd <[email protected]> | 2021-06-30 18:06:12 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-06-30 18:06:12 -0400 |
commit | aa3e29895b6b2b95278fc34d72a69f11befe2bbe (patch) | |
tree | cf1297bd6de0bd4a36ceea855b9588320d9ff801 /src/python | |
parent | 1a9b02423ae00bb00ed2ba0b3ee4087d61272cc7 (diff) |
Capture the FFI exception string in a thread_local variable
Discussion in https://github.com/randombit/botan-rs/issues/16
Diffstat (limited to 'src/python')
-rwxr-xr-x | src/python/botan2.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 24247ceb5..003c98f21 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -40,8 +40,14 @@ class BotanException(Exception): if rc == 0: super(BotanException, self).__init__(message) else: - descr = _DLL.botan_error_description(rc).decode('ascii') - super(BotanException, self).__init__("%s: %d (%s)" % (message, rc, descr)) + exn_msg = _DLL.botan_error_last_exception_message().decode('ascii') + err_descr = _DLL.botan_error_description(rc).decode('ascii') + + formatted_msg = "%s: %d (%s)" % (message, rc, err_descr) + if exn_msg != "": + formatted_msg += ': ' + exn_msg + + super(BotanException, self).__init__(formatted_msg) def error_code(self): return self.__rc @@ -119,6 +125,9 @@ def _set_prototypes(dll): dll.botan_error_description.argtypes = [c_int] dll.botan_error_description.restype = c_char_p + dll.botan_error_last_exception_message.argtypes = [] + dll.botan_error_last_exception_message.restype = c_char_p + # These are generated using src/scripts/ffi_decls.py: ffi_api(dll.botan_constant_time_compare, [c_void_p, c_void_p, c_size_t], [-1]) ffi_api(dll.botan_scrub_mem, [c_void_p, c_size_t]) |