aboutsummaryrefslogblamecommitdiff
path: root/main.go
blob: 70b06bc0c06355e5f9dd74e875446377bc04cf5d (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                                       
            
 
        
             
            

 
       
                          

 
             
























                                                
         

 









                                                                            
           
 
// 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
`, COMMAND)
}