X-Git-Url: https://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fengine.py;fp=ctypescrypto%2Fengine.py;h=c2858e6ebd5b459a1dceac7eac99dc7d5be3388e;hb=287e8a5b1d7f5a8129619f733adbfc8b2de3e4c7;hp=0446d48c2649426fef33ba16ca10b19ae6b0c7d0;hpb=954b6dc9e3312f8d8b49f20f8466e6d2a8342f35;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/engine.py b/ctypescrypto/engine.py index 0446d48..c2858e6 100644 --- a/ctypescrypto/engine.py +++ b/ctypescrypto/engine.py @@ -1,38 +1,39 @@ """ engine loading and configuration """ -from ctypes import * +from ctypes import c_void_p, c_char_p, c_int from ctypescrypto import libcrypto from ctypescrypto.exception import LibCryptoError -__all__=['default','set_default'] +__all__ = ['default', 'set_default'] -default=None +default = None def set_default(engine): """ - Loads specified engine and sets it as default for all - algorithms, supported by it + Loads specified engine and sets it as default for all + algorithms, supported by it """ global default - e=libcrypto.ENGINE_by_id(engine) - if e is None: + eng = libcrypto.ENGINE_by_id(engine) + if eng is None: # Try load engine - e = libcrypto.ENGINE_by_id("dynamic") - if e is None: + eng = libcrypto.ENGINE_by_id("dynamic") + if eng is None: raise LibCryptoError("Cannot get 'dynamic' engine") - if not libcrypto.ENGINE_ctrl_cmd_string(e,"SO_PATH",engine,0): + if not libcrypto.ENGINE_ctrl_cmd_string(eng, "SO_PATH", engine, 0): raise LibCryptoError("Cannot execute ctrl cmd SO_PATH") - if not libcrypto.ENGINE_ctrl_cmd_string(e,"LOAD",None,0): + if not libcrypto.ENGINE_ctrl_cmd_string(eng, "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 + if eng is None: + raise ValueError("Cannot find engine " + engine) + libcrypto.ENGINE_set_default(eng, c_int(0xFFFF)) + default = eng # 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) -libcrypto.ENGINE_finish.argtypes=(c_char_p,) +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) +libcrypto.ENGINE_finish.argtypes = (c_char_p, )