]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - ctypescrypto/engine.py
47f4878d72d9c542a5659002302d72375c46c5b5
[oss/ctypescrypto.git] / ctypescrypto / engine.py
1 from ctypes import *
2 from ctypescrypto import libcrypto
3 from ctypescrypto.exception import LibCryptoError
4 default=None
5
6 def set_default(engine):
7         global default
8         e=libcrypto.ENGINE_by_id(engine)
9         if e is None:
10                 # Try load engine
11                 e = libcrypto.ENGINE_by_id("dynamic")
12                 if  e is None:
13                         raise LibCryptoError("Cannot get 'dynamic' engine")
14                 if not libcrypto.ENGINE_ctrl_cmd_string(e,"SO_PATH",engine,0):
15                         raise LibCryptoError("Cannot execute ctrl cmd SO_PATH")
16                 if not libcrypto.ENGINE_ctrl_cmd_string(e,"LOAD",None,0):
17                         raise LibCryptoError("Cannot execute ctrl cmd LOAD")
18         if e is None:
19                 raise ValueError("Cannot find engine "+engine)
20         libcrypto.ENGINE_set_default(e,c_int(0xFFFF))
21         default=e
22
23 # Declare function result and arguments for used functions
24 libcrypto.ENGINE_by_id.restype=c_void_p
25 libcrypto.ENGINE_by_id.argtypes=(c_char_p,)
26 libcrypto.ENGINE_set_default.argtypes=(c_void_p,c_int)
27 libcrypto.ENGINE_ctrl_cmd_string.argtypes=(c_void_p,c_char_p,c_char_p,c_int)