Check arguments before looking for the mnemonic (closes #79)
check / check (push) Waiting to run
check / check (push) Waiting to run
The key index, --words, the --to recipients and the input file of age encrypt and age decrypt were checked only after the mnemonic had been obtained, so a run that could not succeed still prompted for it or ran the mnemonic command. options.Index now refuses an index above derive.MaxIndex, which covers every command group; the mnemonic command calls the new childmnemonic.CheckWords first; age encrypt reads its recipients with the new agekey.Recipients, and both age commands open their input, before the key is derived. The README says which checks come first. Judgement call: the -o path is still looked at after the mnemonic. Model: opus-5-5
This commit was merged in pull request #84.
This commit is contained in:
@@ -29,6 +29,17 @@ const DefaultWords = twelve
|
||||
// ErrWordCount is returned for a length this tool does not offer.
|
||||
var ErrWordCount = errors.New("a child mnemonic has 12, 18 or 24 words")
|
||||
|
||||
// CheckWords refuses a length this tool does not offer, so that the
|
||||
// command can turn it down before it looks for the mnemonic.
|
||||
func CheckWords(words uint32) error {
|
||||
switch words {
|
||||
case twelve, eighteen, twentyFour:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%w, not %d", ErrWordCount, words)
|
||||
}
|
||||
}
|
||||
|
||||
// Derive returns the English child mnemonic of that many words at that
|
||||
// key index, taken from the master key with BIP-85's own mnemonic
|
||||
// application, number 39. The words come straight from the BIP-85
|
||||
@@ -38,13 +49,12 @@ func Derive(
|
||||
master *hdkeychain.ExtendedKey,
|
||||
words, index uint32,
|
||||
) (string, error) {
|
||||
switch words {
|
||||
case twelve, eighteen, twentyFour:
|
||||
default:
|
||||
return "", fmt.Errorf("%w, not %d", ErrWordCount, words)
|
||||
err := CheckWords(words)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err := derive.CheckIndex(index)
|
||||
err = derive.CheckIndex(index)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user