2 Exception which extracts libcrypto error information
5 from ctypescrypto import libcrypto
8 __all__ = ['LibCryptoError','clear_err_stack']
10 class LibCryptoError(Exception):
12 Exception for libcrypto errors. Adds all the info, which can be
13 extracted from internal (per-thread) libcrypto error stack to the message,
14 passed to the constructor.
16 def __init__(self,msg):
18 if not strings_loaded:
19 libcrypto.ERR_load_crypto_strings()
21 e=libcrypto.ERR_get_error()
24 m+="\n\t"+libcrypto.ERR_lib_error_string(e)+":"+\
25 libcrypto.ERR_func_error_string(e)+":"+\
26 libcrypto.ERR_reason_error_string(e)
27 e=libcrypto.ERR_get_error()
30 def clear_err_stack():
32 Clears internal libcrypto err stack. Call it if you've checked
33 return code and processed exceptional situation, so subsequent
34 raising of the LibCryptoError wouldn't list already handled errors
36 libcrypto.ERR_clear_error()
39 libcrypto.ERR_lib_error_string.restype=c_char_p
40 libcrypto.ERR_func_error_string.restype=c_char_p
41 libcrypto.ERR_reason_error_string.restype=c_char_p