aboutsummaryrefslogtreecommitdiffstats
path: root/src/python/botan2.py
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-06-30 18:06:12 -0400
committerJack Lloyd <[email protected]>2021-06-30 18:06:12 -0400
commitaa3e29895b6b2b95278fc34d72a69f11befe2bbe (patch)
treecf1297bd6de0bd4a36ceea855b9588320d9ff801 /src/python/botan2.py
parent1a9b02423ae00bb00ed2ba0b3ee4087d61272cc7 (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/botan2.py')
-rwxr-xr-xsrc/python/botan2.py13
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])