Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ctypescrypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ctypes import CDLL, c_char_p, c_void_p, c_long,c_uint64
from ctypes.util import find_library
import os
import sys
global strings_loaded

Expand All @@ -18,16 +19,25 @@ def config(filename=None):

__all__ = ['config']

if sys.platform.startswith('win'):
__libname__ = find_library('libeay32')
else:
__libname__ = find_library('crypto')
__libname__ = os.environ.get("CTYPESCRYPTO_LIBCRYPTO")
if __libname__ is None:
if sys.platform.startswith('win'):
__libname__ = find_library('libeay32')
if __libname__ is None:
# Look harder for the version bundled with Python
python_install_dir = os.path.dirname(sys.executable)
dlls_dir = os.path.join(python_install_dir, "DLLs")
if os.path.isdir(dlls_dir):
for f in os.listdir(dlls_dir):
if f.startswith("libcrypto") and f.endswith(".dll"):
__libname__ = os.path.join(dlls_dir, f)
break
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, )
pyver=int(sys.version[0])
Expand Down