mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-07 12:35:14 +00:00
cmd/age-keygen: move to a standalone binary
This commit is contained in:
51
cmd/age-keygen/keygen.go
Normal file
51
cmd/age-keygen/keygen.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/FiloSottile/age/internal/age"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
outFlag := flag.String("o", "", "output to `FILE` (default stdout)")
|
||||
flag.Parse()
|
||||
if len(flag.Args()) != 0 {
|
||||
log.Fatalf("age-keygen takes no arguments")
|
||||
}
|
||||
|
||||
out := os.Stdout
|
||||
if name := *outFlag; name != "" {
|
||||
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open output file %q: %v", name, err)
|
||||
}
|
||||
defer f.Close()
|
||||
out = f
|
||||
}
|
||||
|
||||
generate(out)
|
||||
}
|
||||
|
||||
func generate(out io.Writer) {
|
||||
k, err := age.GenerateX25519Identity()
|
||||
if err != nil {
|
||||
log.Fatalf("Internal error: %v", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "# created: %s\n", time.Now().Format(time.RFC3339))
|
||||
fmt.Fprintf(out, "# %s\n", k.Recipient())
|
||||
fmt.Fprintf(out, "%s\n", k)
|
||||
}
|
||||
Reference in New Issue
Block a user