Browse Source

load_library: remove ctypes.util.find_library calls. remove some code dupe

find_library was giving priority to system dll against local dll
master
SomberNight 8 years ago
parent
commit
7c53712750
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 8
      lib/ecc.py
  2. 17
      lib/ecc_fast.py

8
lib/ecc.py

@ -109,13 +109,7 @@ def ser_to_point(ser: bytes) -> (int, int):
def _ser_to_python_ecdsa_point(ser: bytes) -> ecdsa.ellipticcurve.Point: def _ser_to_python_ecdsa_point(ser: bytes) -> ecdsa.ellipticcurve.Point:
if ser[0] not in (0x02, 0x03, 0x04): x, y = ser_to_point(ser)
raise ValueError('Unexpected first byte: {}'.format(ser[0]))
x = string_to_number(ser[1:33])
if ser[0] == 0x04:
y = string_to_number(ser[33:])
else:
y = get_y_coord_from_x(x, ser[0] == 0x03)
return Point(curve_secp256k1, x, y, CURVE_ORDER) return Point(curve_secp256k1, x, y, CURVE_ORDER)

17
lib/ecc_fast.py

@ -32,18 +32,13 @@ SECP256K1_EC_COMPRESSED = (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BI
SECP256K1_EC_UNCOMPRESSED = (SECP256K1_FLAGS_TYPE_COMPRESSION) SECP256K1_EC_UNCOMPRESSED = (SECP256K1_FLAGS_TYPE_COMPRESSION)
# TODO double check ctypes arg/return value types against https://github.com/bitcoin-core/secp256k1/blob/master/src/secp256k1.c
def load_library(): def load_library():
library_path = ctypes.util.find_library('libsecp256k1') or \ if sys.platform == 'darwin':
ctypes.util.find_library('secp256k1') library_path = 'libsecp256k1.dylib'
if not library_path: elif sys.platform in ('windows', 'win32'):
print_error('[ecc] info: libsecp256k1 library was not found, trying fallback name') library_path = 'libsecp256k1.dll'
if sys.platform == 'darwin': else:
library_path = 'libsecp256k1.dylib' library_path = 'libsecp256k1.so.0'
elif sys.platform in ('windows', 'win32'):
library_path = 'libsecp256k1.dll'
else:
library_path = 'libsecp256k1.so.0'
secp256k1 = ctypes.cdll.LoadLibrary(library_path) secp256k1 = ctypes.cdll.LoadLibrary(library_path)
if not secp256k1: if not secp256k1:

Loading…
Cancel
Save