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:
@@ -94,15 +94,12 @@ func (k *Key) Identity() string {
|
||||
}
|
||||
|
||||
// Encrypt copies src to dst, encrypted to this key and to every extra
|
||||
// recipient named, so the same mnemonic can always read it back again.
|
||||
// recipient given, so the same mnemonic can always read it back again.
|
||||
// Armored output is the text form age also reads.
|
||||
func (k *Key) Encrypt(
|
||||
dst io.Writer, src io.Reader, to []string, armored bool,
|
||||
dst io.Writer, src io.Reader, to []age.Recipient, armored bool,
|
||||
) error {
|
||||
all, err := recipients(k.identity.Recipient(), to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
all := append([]age.Recipient{k.identity.Recipient()}, to...)
|
||||
|
||||
out := dst
|
||||
|
||||
@@ -113,7 +110,7 @@ func (k *Key) Encrypt(
|
||||
out = text
|
||||
}
|
||||
|
||||
err = encrypt(out, src, all)
|
||||
err := encrypt(out, src, all)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -130,12 +127,12 @@ func (k *Key) Encrypt(
|
||||
return nil
|
||||
}
|
||||
|
||||
// recipients returns the key's own recipient followed by the ones
|
||||
// named on the command line, so what the key encrypts it can read.
|
||||
func recipients(mine age.Recipient, to []string) ([]age.Recipient, error) {
|
||||
list := []age.Recipient{mine}
|
||||
// Recipients reads the recipients named on the command line, for
|
||||
// Encrypt to add to the key's own.
|
||||
func Recipients(names []string) ([]age.Recipient, error) {
|
||||
list := make([]age.Recipient, 0, len(names))
|
||||
|
||||
for _, name := range to {
|
||||
for _, name := range names {
|
||||
parsed, err := age.ParseX25519Recipient(name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading recipient %q: %w", name, err)
|
||||
|
||||
Reference in New Issue
Block a user