]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/exception.py
Begin to implement python3 support. Now tests for oid, bio, cipher, digest, mac and...
[oss/ctypescrypto.git] / ctypescrypto / exception.py
index d2866a020c050f4ddf5d5a105b91c60a529f128e..18dc5a4aa17c3164b4bf3a0381e807976a25d994 100644 (file)
@@ -2,10 +2,16 @@
 Exception which extracts libcrypto error information
 """
 from ctypes import c_ulong, c_char_p, create_string_buffer
-from ctypescrypto import libcrypto, strings_loaded
+from ctypescrypto import libcrypto, strings_loaded, pyver
 
 __all__ = ['LibCryptoError', 'clear_err_stack']
 
+if pyver == 2:
+    def _get_error_str(err_code,buf):
+        return libcrypto.ERR_error_string(err_code,buf)
+else:
+    def _get_error_str(err_code,buf):
+        return libcrypto.ERR_error_string(err_code,buf).decode('utf-8')
 class LibCryptoError(Exception):
     """
     Exception for libcrypto errors. Adds all the info, which can be
@@ -21,7 +27,7 @@ class LibCryptoError(Exception):
         mesg = msg
         buf = create_string_buffer(128)
         while err_code != 0:
-            mesg += "\n\t" + libcrypto.ERR_error_string(err_code, buf)
+            mesg += "\n\t" + _get_error_str(err_code, buf)
             err_code = libcrypto.ERR_get_error()
         super(LibCryptoError, self).__init__(mesg)