cmd/age-keygen: print the public key to standard error

This commit is contained in:
Filippo Valsorda
2019-12-27 23:49:09 +01:00
parent 3d73da544d
commit 1bf22e2163

View File

@@ -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)