Skip to content

Commit 9e63088

Browse files
committed
Fix for environments where find_library always fails
1 parent cca794a commit 9e63088

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/atca_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define _ATCA_VERSION_H
3131

3232
// Version format yyyymmdd
33-
#define ATCA_LIBRARY_VERSION_DATE "20210423"
33+
#define ATCA_LIBRARY_VERSION_DATE "20210514"
3434
#define ATCA_LIBRARY_VERSION_MAJOR 3
3535
#define ATCA_LIBRARY_VERSION_MINOR 3
3636
#define ATCA_LIBRARY_VERSION_BUILD 1

python/cryptoauthlib/library.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import os.path
2525
import json
26+
import sys
2627
from ctypes import *
2728
from ctypes.util import find_library
2829
from .exceptions import LibraryLoadError
@@ -69,6 +70,21 @@ def __str__(self):
6970
return str(self.value)
7071

7172

73+
def _force_local_library():
74+
"""
75+
In some environments loading seems to fail under all circumstances unless
76+
brute forcing it.
77+
"""
78+
curr_path = os.path.dirname(__file__)
79+
80+
if sys.platform.startswith('win'):
81+
return os.path.join(curr_path, "cryptoauth.dll")
82+
elif sys.platform.startswith('darwin'):
83+
return os.path.join(curr_path, "libcryptoauth.dylib")
84+
else:
85+
return os.path.join(curr_path, "libcryptoauth.so")
86+
87+
7288
def load_cryptoauthlib(lib=None):
7389
"""
7490
Load CryptoAauthLib into Python environment
@@ -80,7 +96,10 @@ def load_cryptoauthlib(lib=None):
8096
else:
8197
try:
8298
os.environ['PATH'] = os.path.dirname(__file__) + os.pathsep + os.environ['PATH']
83-
_CRYPTO_LIB = cdll.LoadLibrary(find_library('cryptoauth'))
99+
library_file = find_library('cryptoauth')
100+
if library_file is None:
101+
library_file = _force_local_library()
102+
_CRYPTO_LIB = cdll.LoadLibrary(library_file)
84103
except:
85104
raise LibraryLoadError('Unable to find cryptoauthlib. You may need to reinstall')
86105

0 commit comments

Comments
 (0)