]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - ctypescrypto/__init__.py
Begin to implement python3 support. Now tests for oid, bio, cipher, digest, mac and...
[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 pyver=int(sys.version[0])
34 if pyver == 2:
35     bintype = str
36     chartype = unicode
37     inttype = (int, long)
38 else:
39     bintype = bytes
40     chartype = str
41     inttype = int
42
43 if hasattr(libcrypto,'OPENSSL_init_crypto'):
44     libcrypto.OPENSSL_init_crypto.argtypes = (c_uint64,c_void_p)
45     libcrypto.OPENSSL_init_crypto(2+4+8+0x40,None)
46     strings_loaded = True
47 else:     
48     libcrypto.OPENSSL_add_all_algorithms_conf()
49     strings_loaded = False