diff --git a/lib/atca_version.h b/lib/atca_version.h index 9b6dc5c3d..b2eccb5fc 100644 --- a/lib/atca_version.h +++ b/lib/atca_version.h @@ -30,7 +30,7 @@ #define _ATCA_VERSION_H // Version format yyyymmdd -#define ATCA_LIBRARY_VERSION_DATE "20210423" +#define ATCA_LIBRARY_VERSION_DATE "20210514" #define ATCA_LIBRARY_VERSION_MAJOR 3 #define ATCA_LIBRARY_VERSION_MINOR 3 #define ATCA_LIBRARY_VERSION_BUILD 1 diff --git a/python/cryptoauthlib/library.py b/python/cryptoauthlib/library.py index 514a0f617..390fbddc5 100644 --- a/python/cryptoauthlib/library.py +++ b/python/cryptoauthlib/library.py @@ -23,6 +23,7 @@ import os.path import json +import sys from ctypes import * from ctypes.util import find_library from .exceptions import LibraryLoadError @@ -69,6 +70,21 @@ def __str__(self): return str(self.value) +def _force_local_library(): + """ + In some environments loading seems to fail under all circumstances unless + brute forcing it. + """ + curr_path = os.path.dirname(__file__) + + if sys.platform.startswith('win'): + return os.path.join(curr_path, "cryptoauth.dll") + elif sys.platform.startswith('darwin'): + return os.path.join(curr_path, "libcryptoauth.dylib") + else: + return os.path.join(curr_path, "libcryptoauth.so") + + def load_cryptoauthlib(lib=None): """ Load CryptoAauthLib into Python environment @@ -80,7 +96,10 @@ def load_cryptoauthlib(lib=None): else: try: os.environ['PATH'] = os.path.dirname(__file__) + os.pathsep + os.environ['PATH'] - _CRYPTO_LIB = cdll.LoadLibrary(find_library('cryptoauth')) + library_file = find_library('cryptoauth') + if library_file is None: + library_file = _force_local_library() + _CRYPTO_LIB = cdll.LoadLibrary(library_file) except: raise LibraryLoadError('Unable to find cryptoauthlib. You may need to reinstall')