Skip to content

Commit

Permalink
cmd/age: improve incorrect passphrase error message
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
FiloSottile committed Dec 31, 2019
1 parent 7935150 commit e43cf8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/age/encrypted_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ func (i *LazyScryptIdentity) Unwrap(block *format.Recipient) (fileKey []byte, er
if err != nil {
return nil, err
}
return ii.Unwrap(block)
fileKey, err = ii.Unwrap(block)
if err == age.ErrIncorrectIdentity {
// The API will just ignore the identity if the passphrase is wrong, and
// move on, eventually returning "no identity matched a recipient".
// Since we only supply one identity from the CLI, make it a fatal
// error with a better message.
return nil, fmt.Errorf("incorrect passphrase")
}
return fileKey, err
}

// stdinInUse is set in main. It's a singleton like os.Stdin.
Expand Down
3 changes: 3 additions & 0 deletions internal/age/age.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ RecipientsLoop:
fileKey, err = i.Unwrap(r)
if err != nil {
if err == ErrIncorrectIdentity {
// TODO: we should collect these errors and return them as an
// []error type with an Error method. That will require turning
// ErrIncorrectIdentity into an interface or wrapper error.
continue
}
return nil, err
Expand Down

0 comments on commit e43cf8b

Please sign in to comment.