aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 6999c48189cb67fb90bc69131c7651eb8a62d504 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// This package builds a binary which helps to generate
// private keys, public keys, certificates and also
// includes functionality to sign and verify messages.
package main

import (
	"fmt"
	"os"
)

const (
	COMMAND = "pkictl"
)

func main() {
	if len(os.Args) == 1 {
		printHelp()
		return
	}
	command, args := os.Args[1], os.Args[2:]
	var err error
	switch command {
	case "create-private":
		err = CreatePrivateKey(args)
	case "create-public":
		err = CreatePublicKey(args)
	case "sign-input":
		err = SignInput(args)
	case "verify-input":
		err = VerifyInput(args)
	case "create-sign-request":
		err = CreateSignRequest(args)
	case "create-cert":
		err = CreateCert(args)
	default:
		printHelp()
	}
	if err != nil {
		fmt.Printf("error: %s\n", err)
		os.Exit(2)
	}
}

func printHelp() {
	fmt.Printf(`Usage: %s command [flags]

where 'command' is one of:
  create-private        create a private key
  create-public         create a public key derived from a private key
  sign-input            sign a message using a private key
  verify-input          verify a message using a signature and a public key
  create-sign-request   create a certificate sign request
  create-cert           create a certificate from a certificate sign request
  diff                  show the differences between two certificates
`, COMMAND)
}