Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hwilib/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,11 @@ def _get_func_expr(s: str) -> Tuple[str, str]:
try:
start = s.index("(")
end = s.rindex(")")
return s[0:start], s[start + 1:end]
except ValueError:
raise ValueError("A matching pair of parentheses cannot be found")
if end != len(s) - 1:
raise ValueError("Trailing characters '{}' after descriptor".format(s[end + 1:]))
return s[0:start], s[start + 1:end]


def _get_const(s: str, const: str) -> str:
Expand Down
7 changes: 7 additions & 0 deletions test/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ def test_parse_descriptor_with_key_at_end_without_origin(self):
def test_parse_empty_descriptor(self):
self.assertRaises(ValueError, parse_descriptor, "")

def test_parse_descriptor_trailing_characters(self):
key = "02c97dc3f4420402e01a113984311bf4a1b8de376cac0bdcfaf1b3ac81f13433c7"
with self.assertRaisesRegex(ValueError, "Trailing characters"):
parse_descriptor("pkh({})abc".format(key))
with self.assertRaisesRegex(ValueError, "Trailing characters"):
parse_descriptor("sh(wpkh({}))x".format(key))

def test_parse_descriptor_replace_h(self):
d = "wpkh([00000001/84h/1h/0h]tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/0/0)"
desc = parse_descriptor(d)
Expand Down
Loading