diff options
author | Linus Nordberg <linus@nordberg.se> | 2022-04-28 15:46:01 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2022-04-28 15:46:01 +0200 |
commit | 47490448be1b7006641e6badc6a84b1441b27698 (patch) | |
tree | fb386e9e6ccb90b368da63d0a8085d114fd8431c /cmd/sigsum-debug/key/key.go | |
parent | 2dcd7bca2f3e69fb6f1770ec0bf740d8956978ca (diff) | |
parent | b270a4c0d10947fe480bad7330b31bb793225968 (diff) |
Merge branch 'merge/sigsum-debug'
Diffstat (limited to 'cmd/sigsum-debug/key/key.go')
-rw-r--r-- | cmd/sigsum-debug/key/key.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cmd/sigsum-debug/key/key.go b/cmd/sigsum-debug/key/key.go new file mode 100644 index 0000000..88973f2 --- /dev/null +++ b/cmd/sigsum-debug/key/key.go @@ -0,0 +1,51 @@ +package key + +import ( + "flag" + "fmt" + "log" + + "git.sigsum.org/sigsum-go/cmd/sigsum-debug/key/hash" + "git.sigsum.org/sigsum-go/cmd/sigsum-debug/key/private" + "git.sigsum.org/sigsum-go/cmd/sigsum-debug/key/public" + "git.sigsum.org/sigsum-go/internal/options" +) + +const usage = ` +sigsum-debug key generates private keys, public keys, and key hashes. + +Usage: + + sigsum-debug key help Outputs a usage message + sigsum-debug key private Outputs a new private key + sigsum-debug key public Outputs a public key for a private key on stdin + sigsum-debug key hash Outputs a key hash for a public key on stdin + +` + +func Main(args []string) error { + var err error + + opt := options.New(args, func() { log.Printf(usage[1:]) }, func(_ *flag.FlagSet) {}) + switch opt.Name() { + case "help": + opt.Usage() + case "private": + err = private.Main(opt.Args()) + case "public": + err = public.Main(opt.Args()) + case "hash": + err = hash.Main(opt.Args()) + default: + err = fmt.Errorf("invalid command %q, try \"help\"", opt.Name()) + } + if err != nil { + format := " %s: %w" + if len(opt.Name()) == 0 { + format = "%s: %w" + } + err = fmt.Errorf(format, opt.Name(), err) + } + + return err +} |