mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-08 13:01:09 +00:00
cmd/age: improve error message when -i is missing
This commit is contained in:
@@ -466,7 +466,7 @@ func decryptPass(in io.Reader, out io.Writer) {
|
||||
identities := []age.Identity{
|
||||
// If there is an scrypt recipient (it will have to be the only one and)
|
||||
// this identity will be invoked.
|
||||
&LazyScryptIdentity{passphrasePromptForDecryption},
|
||||
lazyScryptIdentity,
|
||||
}
|
||||
|
||||
decrypt(identities, in, out)
|
||||
@@ -492,6 +492,10 @@ func decrypt(identities []age.Identity, in io.Reader, out io.Writer) {
|
||||
errorWithHint(err.Error(),
|
||||
fmt.Sprintf("you might want to install the %q plugin", e.Name),
|
||||
"visit https://age-encryption.org/awesome#plugins for a list of available plugins")
|
||||
} else if errors.As(err, new(*age.NoIdentityMatchError)) &&
|
||||
len(identities) == 1 && identities[0] == lazyScryptIdentity {
|
||||
errorWithHint("the file is not passphrase-encrypted, identities are required",
|
||||
"specify identities with -i/--identity or -j to decrypt this file")
|
||||
} else if err != nil {
|
||||
errorf("%v", err)
|
||||
}
|
||||
@@ -501,6 +505,8 @@ func decrypt(identities []age.Identity, in io.Reader, out io.Writer) {
|
||||
}
|
||||
}
|
||||
|
||||
var lazyScryptIdentity = &LazyScryptIdentity{passphrasePromptForDecryption}
|
||||
|
||||
func passphrasePromptForDecryption() (string, error) {
|
||||
pass, err := readSecret("Enter passphrase:")
|
||||
if err != nil {
|
||||
|
||||
5
cmd/age/testdata/scrypt.txt
vendored
5
cmd/age/testdata/scrypt.txt
vendored
@@ -42,6 +42,11 @@ ttyin wrong
|
||||
stderr 'passphrases didn''t match'
|
||||
! exists fail.age
|
||||
|
||||
# fail when -i is missing
|
||||
age -r age1xmwwc06ly3ee5rytxm9mflaz2u56jjj36s0mypdrwsvlul66mv4q47ryef -o test.age input
|
||||
! age -d test.age
|
||||
stderr 'file is not passphrase-encrypted, identities are required'
|
||||
|
||||
-- terminal --
|
||||
password
|
||||
password
|
||||
|
||||
Reference in New Issue
Block a user