Skip to content

Commit b2aafe3

Browse files
committed
correct: classify malformed HRPs as usage
1 parent 4711682 commit b2aafe3

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎src/codex32/cli.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ def _correct(
544544
separator = normalized.lower().rfind("1")
545545
if separator <= 0:
546546
raise _UsageError("Enter a complete application prefix followed by the separator 1.")
547-
hrp = normalized[:separator].lower()
547+
raw_hrp = normalized[:separator]
548+
if len(raw_hrp) > 83 or any(not 33 <= ord(character) <= 126 for character in raw_hrp):
549+
raise _UsageError("The application prefix must be at most 83 printable ASCII characters.")
550+
hrp = raw_hrp.lower()
548551
if context.master_seed and hrp != Profile.MS.value:
549552
raise _UsageError("This command accepts only Bitcoin master-seed input beginning with ms1.")
550553
try:

‎tests/test_cli.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,15 @@ def test_cli_rejects_sixteen_consecutive_erasures_as_outside_regular_bound() ->
17281728
assert "No valid correction found" in result.stderr
17291729

17301730

1731+
def test_correct_rejects_malformed_immutable_hrp_as_usage() -> None:
1732+
damaged = "é" + VECTOR_1["secret_s"][1:]
1733+
1734+
result = _invoke(["correct"], damaged)
1735+
1736+
assert result.exit_code == 2
1737+
assert "application prefix" in result.stderr
1738+
1739+
17311740
@pytest.mark.parametrize(
17321741
("byte_length", "options"),
17331742
((16, []), (64, []), (20, ["--bytes", "20"]), (24, ["--bytes", "?"])),

0 commit comments

Comments
 (0)