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