]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - ctypescrypto/__init__.py
Fix incompatibilities with OpenSSL 1.1.0
[oss/ctypescrypto.git] / ctypescrypto / __init__.py
1 """
2     Interface to some libcrypto functions
3
4 """
5
6
7 from ctypes import CDLL, c_char_p, c_void_p, c_long,c_uint64
8 from ctypes.util import find_library
9 import sys
10 global strings_loaded
11
12 def config(filename=None):
13     """
14         Loads OpenSSL Config file. If none are specified, loads default
15         (compiled in) one
16     """
17     libcrypto.OPENSSL_config(filename)
18
19 __all__ = ['config']
20
21 if sys.platform.startswith('win'):
22     __libname__ = find_library('libeay32')
23 else:
24     __libname__ = find_library('crypto')
25
26 if __libname__ is None:
27     raise OSError("Cannot find OpenSSL crypto library")
28
29 #__libname__ = "/usr/local/ssl/lib/libcrypto.so.1.1"
30
31 libcrypto = CDLL(__libname__)
32 libcrypto.OPENSSL_config.argtypes = (c_char_p, )
33
34 if hasattr(libcrypto,'OPENSSL_init_crypto'):
35     libcrypto.OPENSSL_init_crypto.argtypes = (c_uint64,c_void_p)
36     libcrypto.OPENSSL_init_crypto(2+4+8+0x40,None)
37     strings_loaded = True
38 else:     
39     libcrypto.OPENSSL_add_all_algorithms_conf()
40     strings_loaded = False