Skip to content

Commit

Permalink
cmd/age-keygen: print the public key to standard error
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Dec 27, 2019
1 parent 3d73da5 commit 1bf22e2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/age-keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1bf22e2

Please sign in to comment.