2 Exception which extracts libcrypto error information
5 from ctypescrypto import libcrypto
7 class LibCryptoError(Exception):
9 Exception for libcrypto errors. Adds all the info, which can be
10 extracted from internal (per-thread) libcrypto error stack to the message,
11 passed to the constructor.
13 def __init__(self,msg):
15 if not strings_loaded:
16 libcrypto.ERR_load_crypto_strings()
18 e=libcrypto.ERR_get_error()
21 m+="\n\t"+libcrypto.ERR_lib_error_string(e)+":"+\
22 libcrypto.ERR_func_error_string(e)+":"+\
23 libcrypto.ERR_reason_error_string(e)
24 e=libcrypto.ERR_get_error()
27 def clear_err_stack():
29 Clears internal libcrypto err stack. Call it if you've checked
30 return code and processed exceptional situation, so subsequent
31 raising of the LibCryptoError wouldn't list already handled errors
33 libcrypto.ERR_clear_error()
36 libcrypto.ERR_lib_error_string.restype=c_char_p
37 libcrypto.ERR_func_error_string.restype=c_char_p
38 libcrypto.ERR_reason_error_string.restype=c_char_p