X-Git-Url: https://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2F__init__.py;h=a63fed425bdd9abe07d09ce915bb17030968f376;hb=876630b04080b68d724e22066d374ce25efd8a97;hp=b6d00cacb75c7429a017d9b55997e2ba3afe3b88;hpb=1ff9b1899959673512927b6afa317855908b7073;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/__init__.py b/ctypescrypto/__init__.py index b6d00ca..a63fed4 100644 --- a/ctypescrypto/__init__.py +++ b/ctypescrypto/__init__.py @@ -1,9 +1,40 @@ """ - Interface to some libcrypto functions + Interface to some libcrypto functions """ -from ctypes import CDLL -libcrypto = CDLL("libcrypto.so.1.0.0") -libcrypto.OPENSSL_config(None) +from ctypes import CDLL, c_char_p, c_void_p, c_long,c_uint64 +from ctypes.util import find_library +import sys +global strings_loaded + +def config(filename=None): + """ + Loads OpenSSL Config file. If none are specified, loads default + (compiled in) one + """ + libcrypto.OPENSSL_config(filename) + +__all__ = ['config'] + +if sys.platform.startswith('win'): + __libname__ = find_library('libeay32') +else: + __libname__ = find_library('crypto') + +if __libname__ is None: + raise OSError("Cannot find OpenSSL crypto library") + +#__libname__ = "/usr/local/ssl/lib/libcrypto.so.1.1" + +libcrypto = CDLL(__libname__) +libcrypto.OPENSSL_config.argtypes = (c_char_p, ) + +if hasattr(libcrypto,'OPENSSL_init_crypto'): + libcrypto.OPENSSL_init_crypto.argtypes = (c_uint64,c_void_p) + libcrypto.OPENSSL_init_crypto(2+4+8+0x40,None) + strings_loaded = True +else: + libcrypto.OPENSSL_add_all_algorithms_conf() + strings_loaded = False