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
3.2.x
SomberNight 7 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:
if ser[0] not in (0x02, 0x03, 0x04):
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)
x, y = ser_to_point(ser)
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)
# TODO double check ctypes arg/return value types against https://github.com/bitcoin-core/secp256k1/blob/master/src/secp256k1.c
def load_library():
library_path = ctypes.util.find_library('libsecp256k1') or \
ctypes.util.find_library('secp256k1')
if not library_path:
print_error('[ecc] info: libsecp256k1 library was not found, trying fallback name')
if sys.platform == 'darwin':
library_path = 'libsecp256k1.dylib'
elif sys.platform in ('windows', 'win32'):
library_path = 'libsecp256k1.dll'
else:
library_path = 'libsecp256k1.so.0'
if sys.platform == 'darwin':
library_path = 'libsecp256k1.dylib'
elif sys.platform in ('windows', 'win32'):
library_path = 'libsecp256k1.dll'
else:
library_path = 'libsecp256k1.so.0'
secp256k1 = ctypes.cdll.LoadLibrary(library_path)
if not secp256k1:

Loading…
Cancel
Save