]> wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/exception.py
Added support for MAC
[oss/ctypescrypto.git] / ctypescrypto / exception.py
index f0f3c5343238cabcd382c68ebe03e9738760c7fc..30c138e43aa5ba52651243267abe0cdf974244fa 100644 (file)
@@ -1,6 +1,21 @@
+"""
+Exception which extracts libcrypto error information
+"""
 from ctypes import *
 from ctypescrypto import libcrypto
 strings_loaded=False
+
+__all__ = ['LibCryptoError','clear_err_stack']
+
+def _check_null(s):
+       """
+       Handle transparently NULL returned from error reporting functions
+       instead of strings
+       """
+       if s is None:   
+               return ""
+       return s
+
 class LibCryptoError(Exception):
        """
                Exception for libcrypto errors. Adds all the info, which can be
@@ -15,9 +30,9 @@ class LibCryptoError(Exception):
                e=libcrypto.ERR_get_error()
                m = msg
                while e != 0:
-                       m+="\n\t"+libcrypto.ERR_lib_error_string(e)+":"+\
-                         libcrypto.ERR_func_error_string(e)+":"+\
-                         libcrypto.ERR_reason_error_string(e)
+                       m+="\n\t"+_check_null(libcrypto.ERR_lib_error_string(e))+":"+\
+                         _check_null(libcrypto.ERR_func_error_string(e))+":"+\
+                         _check_null(libcrypto.ERR_reason_error_string(e))
                        e=libcrypto.ERR_get_error()
                self.args=(m,)