X-Git-Url: https://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fengine.py;fp=ctypescrypto%2Fengine.py;h=47f4878d72d9c542a5659002302d72375c46c5b5;hb=1ff9b1899959673512927b6afa317855908b7073;hp=0000000000000000000000000000000000000000;hpb=7b229d0dba6fc42eddf3c359c3d9510330a1eeaf;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/engine.py b/ctypescrypto/engine.py new file mode 100644 index 0000000..47f4878 --- /dev/null +++ b/ctypescrypto/engine.py @@ -0,0 +1,27 @@ +from ctypes import * +from ctypescrypto import libcrypto +from ctypescrypto.exception import LibCryptoError +default=None + +def set_default(engine): + global default + e=libcrypto.ENGINE_by_id(engine) + if e is None: + # Try load engine + e = libcrypto.ENGINE_by_id("dynamic") + if e is None: + raise LibCryptoError("Cannot get 'dynamic' engine") + if not libcrypto.ENGINE_ctrl_cmd_string(e,"SO_PATH",engine,0): + raise LibCryptoError("Cannot execute ctrl cmd SO_PATH") + if not libcrypto.ENGINE_ctrl_cmd_string(e,"LOAD",None,0): + raise LibCryptoError("Cannot execute ctrl cmd LOAD") + if e is None: + raise ValueError("Cannot find engine "+engine) + libcrypto.ENGINE_set_default(e,c_int(0xFFFF)) + default=e + +# Declare function result and arguments for used functions +libcrypto.ENGINE_by_id.restype=c_void_p +libcrypto.ENGINE_by_id.argtypes=(c_char_p,) +libcrypto.ENGINE_set_default.argtypes=(c_void_p,c_int) +libcrypto.ENGINE_ctrl_cmd_string.argtypes=(c_void_p,c_char_p,c_char_p,c_int)