diff --git a/cmd/age-keygen/keygen.go b/cmd/age-keygen/keygen.go index d0b4e20f..80f2d697 100644 --- a/cmd/age-keygen/keygen.go +++ b/cmd/age-keygen/keygen.go @@ -9,12 +9,12 @@ package main import ( "flag" "fmt" - "io" "log" "os" "time" "filippo.io/age/internal/age" + "golang.org/x/crypto/ssh/terminal" ) func main() { @@ -46,12 +46,16 @@ func main() { generate(out) } -func generate(out io.Writer) { +func generate(out *os.File) { k, err := age.GenerateX25519Identity() if err != nil { log.Fatalf("Internal error: %v", err) } + if !terminal.IsTerminal(int(out.Fd())) { + fmt.Fprintf(os.Stderr, "Public key: %s\n", k.Recipient()) + } + fmt.Fprintf(out, "# created: %s\n", time.Now().Format(time.RFC3339)) fmt.Fprintf(out, "# public key: %s\n", k.Recipient()) fmt.Fprintf(out, "%s\n", k)