aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 5265adad121a63bb201204451916fafd27dcd0db (plain)
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
package main

import (
	"errors"
	"fmt"
	"os"
)

var mainUsage = []string{
	"-C [-q] -p pubkey -x sigfile [file ...]",
	"-G [-n] [-c comment] -p pubkey -s seckey",
	"-S [-ez] [-x sigfile] -s seckey -m message",
	"-V [-eqz] [-p pubkey] [-t keytype] [-x sigfile] -m message",
}

var ErrEZ = errors.New("can't combine -e and -z options")

func usage() {
	fmt.Println("Usage:")
	for _, u := range mainUsage {
		fmt.Printf("%v %v\n", progName(), u)
	}
	os.Exit(2)
}

func fail(err error) {
	fmt.Println(err)
	os.Exit(1)
}

var modes = map[string]func([]string) error{
	"-C": check,
	"-G": generate,
	"-S": sign,
	"-V": verify,
}

func main() {
	if len(os.Args) < 2 {
		usage()
	}
	mode, ok := modes[os.Args[1]]
	if !ok {
		usage()
	}
	if err := mode(os.Args[2:]); err != nil {
		fail(err)
	}
}