Read --index and --words as decimal numbers (closes #75) #81

Merged
clawbot merged 1 commits from issue-75-decimal-index into next 2026-10-13 02:29:26 +02:00
Collaborator

Fixes #75.

--index/-n and --words were uint32 flags, which the flag library reads with Go's base-0 rules: -n 010 derived key 8, and 0x10 and 1_0 were accepted. Both flags now hold an options.Decimal, a small type implementing the flag library's value interface, whose Set parses with strconv.ParseUint(text, 10, 32). A leading zero stays decimal (-n 010 is index 10, --words 012 is 12); a base prefix, an underscore, a sign or an empty value is refused with an error naming the flag. That happens while the flags are parsed, so before any command runs or the mnemonic is looked for, keyfunc ssh -n 0x10 and keyfunc -n 0x10 --version included.

Type still returns uint32, so --help reads as before. GetUint32 checks that name and then parses the value's own decimal text, so options.Index and the read of --words are unchanged.

An index above the largest key index, or a word count other than 12, 18 or 24, is still refused only after the mnemonic is read, as on next; that is #79.

The README says, where it defines n, that the index is a decimal number.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/keyfunc/issues/75. `--index`/`-n` and `--words` were `uint32` flags, which the flag library reads with Go's base-0 rules: `-n 010` derived key 8, and `0x10` and `1_0` were accepted. Both flags now hold an `options.Decimal`, a small type implementing the flag library's value interface, whose `Set` parses with `strconv.ParseUint(text, 10, 32)`. A leading zero stays decimal (`-n 010` is index 10, `--words 012` is 12); a base prefix, an underscore, a sign or an empty value is refused with an error naming the flag. That happens while the flags are parsed, so before any command runs or the mnemonic is looked for, `keyfunc ssh -n 0x10` and `keyfunc -n 0x10 --version` included. `Type` still returns `uint32`, so `--help` reads as before. `GetUint32` checks that name and then parses the value's own decimal text, so `options.Index` and the read of `--words` are unchanged. An index above the largest key index, or a word count other than 12, 18 or 24, is still refused only after the mnemonic is read, as on `next`; that is https://git.eeqj.de/sneak/keyfunc/issues/79. The README says, where it defines `n`, that the index is a decimal number. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 01:19:49 +02:00
clawbot self-assigned this 2026-10-13 01:19:49 +02:00
Author
Collaborator
  1. internal/cli/options/options.go (Add, Decimal) and internal/cli/mnemonic/mnemonic.go: --index and --words are now string flags, parsed by hand when a key is derived. The repo's Go style guide asks for the flag library's value interface over custom flag parsing, and hand parsing is what forces both judgement calls in the PR body. --help shows numbers with quoted string defaults ((default "0"), (default "12")). The --words usage is reworded around a back-quoted word, and Decimal needs a comment about how --help picks a type name. A malformed index is also accepted silently where nothing is derived (keyfunc ssh -n 0x10, keyfunc -n 0x10 --version). Acceptable: one small type implementing that value interface, whose Set parses with strconv.ParseUint(text, 10, 32), used by both flags. --help then reads as before (uint32, (default 12)), and a malformed value is refused, naming the flag, while flags are parsed, before any command runs or the mnemonic is looked for.

  2. derived in internal/cli/ssh/ssh.go, internal/cli/age/age.go and internal/cli/mnemonic/mnemonic.go: some values are refused only after the mnemonic command has run or the mnemonic has been prompted for. These are an index above the largest key index that still fits in 32 bits (-n 2147483648) and a word count other than 12, 18 or 24 (--words 13). -n 4294967296 and --words 0x18 are refused before. Acceptable: both are refused, naming the flag, before the mnemonic is looked for, with a test that uses a failing mnemonic command as the new tests do.

Judgement call: finding 2 reads "refused before the mnemonic is looked for" as also covering values out of range; on next those were already refused after the mnemonic was looked for.

Model: opus-5-5

1. `internal/cli/options/options.go` (`Add`, `Decimal`) and `internal/cli/mnemonic/mnemonic.go`: `--index` and `--words` are now string flags, parsed by hand when a key is derived. The repo's Go style guide asks for the flag library's value interface over custom flag parsing, and hand parsing is what forces both judgement calls in the PR body. `--help` shows numbers with quoted string defaults (`(default "0")`, `(default "12")`). The `--words` usage is reworded around a back-quoted word, and `Decimal` needs a comment about how `--help` picks a type name. A malformed index is also accepted silently where nothing is derived (`keyfunc ssh -n 0x10`, `keyfunc -n 0x10 --version`). Acceptable: one small type implementing that value interface, whose `Set` parses with `strconv.ParseUint(text, 10, 32)`, used by both flags. `--help` then reads as before (`uint32`, `(default 12)`), and a malformed value is refused, naming the flag, while flags are parsed, before any command runs or the mnemonic is looked for. 2. `derived` in `internal/cli/ssh/ssh.go`, `internal/cli/age/age.go` and `internal/cli/mnemonic/mnemonic.go`: some values are refused only after the mnemonic command has run or the mnemonic has been prompted for. These are an index above the largest key index that still fits in 32 bits (`-n 2147483648`) and a word count other than 12, 18 or 24 (`--words 13`). `-n 4294967296` and `--words 0x18` are refused before. Acceptable: both are refused, naming the flag, before the mnemonic is looked for, with a test that uses a failing mnemonic command as the new tests do. Judgement call: finding 2 reads "refused before the mnemonic is looked for" as also covering values out of range; on `next` those were already refused after the mnemonic was looked for. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-13 01:35:51 +02:00
clawbot added 1 commit 2026-10-13 02:03:02 +02:00
Both flags were uint32 flags, which the flag library reads with Go's
base-0 rules, so `-n 010` derived key 8 and `0x10` or `1_0` were
accepted. Both now hold an options.Decimal, a flag value whose Set
parses with strconv.ParseUint(text, 10, 32): a leading zero stays
decimal, and a base prefix, an underscore, a sign or an empty value
is refused with an error naming the flag while the flags are parsed,
before any command runs. Its type is still named uint32, so --help is
unchanged and GetUint32 still reads it back. The README says the index
is a decimal number.

Model: opus-5-5
clawbot force-pushed issue-75-decimal-index from dc3a0150f3 to c3c7108ed7 2026-10-13 02:03:02 +02:00 Compare
Author
Collaborator

Rework:

  1. The string flags and their hand parsing are gone: --index/-n and --words hold options.Decimal, a flag value whose Set parses with strconv.ParseUint(text, 10, 32), so --help is as on next and a malformed value is refused, naming the flag, while flags are parsed (keyfunc ssh -n 0x10 and keyfunc -n 0x10 --version included, with a test); both judgement calls are dropped.
  2. Left out: refusing out-of-range values before the mnemonic is read is #79, kept for the owner.

Model: opus-5-5

Rework: 1. The string flags and their hand parsing are gone: `--index`/`-n` and `--words` hold `options.Decimal`, a flag value whose `Set` parses with `strconv.ParseUint(text, 10, 32)`, so `--help` is as on `next` and a malformed value is refused, naming the flag, while flags are parsed (`keyfunc ssh -n 0x10` and `keyfunc -n 0x10 --version` included, with a test); both judgement calls are dropped. 2. Left out: refusing out-of-range values before the mnemonic is read is https://git.eeqj.de/sneak/keyfunc/issues/79, kept for the owner. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-13 02:03:26 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit efca0ebb39 into next 2026-10-13 02:29:26 +02:00
clawbot deleted branch issue-75-decimal-index 2026-10-13 02:29:26 +02:00
Sign in to join this conversation.