From 1bf22e21636c30ef45920e626d002d00d4ed0896 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Fri, 27 Dec 2019 23:49:09 +0100 Subject: [PATCH] cmd/age-keygen: print the public key to standard error --- cmd/age-keygen/keygen.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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)