Skip to content

Commit a821de8

Browse files
CData: add string representation
1 parent 59ab534 commit a821de8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal_filesystem/lib/secp256k1_compat.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def __init__(self, data, type_str):
1414
self._data = data
1515
self._type = type_str
1616

17+
def __str__(self):
18+
# Return a readable string with type and hex data
19+
if isinstance(self._data, (bytes, bytearray)):
20+
return f"{self._type}: {self._data.hex()}"
21+
elif isinstance(self._data, list):
22+
return f"{self._type}: {bytes(self._data).hex()}"
23+
return f"{self._type}: {self._data}"
24+
25+
def __repr__(self):
26+
# More detailed representation, similar to __str__ but with memory address
27+
return f"<CData {self._type} at {hex(id(self))}, data={self._data.hex() if isinstance(self._data, (bytes, bytearray)) else self._data}>"
28+
1729
# Dummy ffi class to mimic cffi
1830
class FFI:
1931
NULL = None # Mimic cffi's NULL pointer
@@ -430,7 +442,8 @@ def secp256k1_ecdh(self, ctx, output, pubkey, seckey, hashfn=FFI.NULL, hasharg=F
430442
return 0
431443
output[:32] = result
432444
return 1
433-
except ValueError:
445+
except ValueError as e:
446+
print(f"secp256k1_compat.py secp256k1_ecdh got ValueError: {e}")
434447
return 0
435448

436449
# Instantiate ffi and lib

0 commit comments

Comments
 (0)