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