diff --git a/cmd/age/encrypted_keys.go b/cmd/age/encrypted_keys.go index ed77651..93ed38a 100644 --- a/cmd/age/encrypted_keys.go +++ b/cmd/age/encrypted_keys.go @@ -45,15 +45,15 @@ func (i *LazyScryptIdentity) Unwrap(stanzas []*age.Stanza) (fileKey []byte, err return fileKey, err } -// stdinInUse is set in main. It's a singleton like os.Stdin. -var stdinInUse bool - +// readPassphrase reads a passphrase from the terminal. If stdin is not +// connected to a terminal, it tries /dev/tty and fails if that's not available. +// It does not read from a non-terminal stdin, so it does not check stdinInUse. func readPassphrase() ([]byte, error) { fd := int(os.Stdin.Fd()) - if !terminal.IsTerminal(fd) || stdinInUse { + if !terminal.IsTerminal(fd) { tty, err := os.Open("/dev/tty") if err != nil { - return nil, fmt.Errorf("standard input is not available or not a terminal, and opening /dev/tty failed: %v", err) + return nil, fmt.Errorf("standard input is not a terminal, and opening /dev/tty failed: %v", err) } defer tty.Close() fd = int(tty.Fd()) diff --git a/cmd/age/parse.go b/cmd/age/parse.go index 9a7faa1..607cdfb 100644 --- a/cmd/age/parse.go +++ b/cmd/age/parse.go @@ -22,6 +22,9 @@ import ( "golang.org/x/crypto/ssh" ) +// stdinInUse is set in main. It's a singleton like os.Stdin. +var stdinInUse bool + func parseRecipient(arg string) (age.Recipient, error) { switch { case strings.HasPrefix(arg, "age1"):