2 Exception which extracts libcrypto error information
5 from ctypescrypto import libcrypto
8 __all__ = ['LibCryptoError','clear_err_stack']
12 Handle transparently NULL returned from error reporting functions
19 class LibCryptoError(Exception):
21 Exception for libcrypto errors. Adds all the info, which can be
22 extracted from internal (per-thread) libcrypto error stack to the message,
23 passed to the constructor.
25 def __init__(self,msg):
27 if not strings_loaded:
28 libcrypto.ERR_load_crypto_strings()
30 e=libcrypto.ERR_get_error()
33 m+="\n\t"+_check_null(libcrypto.ERR_lib_error_string(e))+":"+\
34 _check_null(libcrypto.ERR_func_error_string(e))+":"+\
35 _check_null(libcrypto.ERR_reason_error_string(e))
36 e=libcrypto.ERR_get_error()
39 def clear_err_stack():
41 Clears internal libcrypto err stack. Call it if you've checked
42 return code and processed exceptional situation, so subsequent
43 raising of the LibCryptoError wouldn't list already handled errors
45 libcrypto.ERR_clear_error()
48 libcrypto.ERR_lib_error_string.restype=c_char_p
49 libcrypto.ERR_func_error_string.restype=c_char_p
50 libcrypto.ERR_reason_error_string.restype=c_char_p