forked from OpenICP-BR/libICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (89 loc) · 2.56 KB
/
main.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"os"
clix "github.com/mkideal/cli/ext"
"github.com/mkideal/cli"
)
var FgGreen = "\u001b[32m"
var Bold = "\u001b[1m"
var Reset = "\u001b[0m"
var help = cli.HelpCommand("display help information (see man page for examples)")
type rootT struct {
cli.Helper
CACache string `cli:"C,ca-cache" usage:"sets the directory that holds the CAs" dft:"$HOME/.cache/OpenICP-BR/CAs"`
FakeRootCA string `cli:"fake-root-ca" usage:"path to a testing CA (only for testing) (do not touch this)"`
}
var root = &cli.Command{
Argv: func() interface{} { return new(rootT) },
Fn: func(ctx *cli.Context) error {
help.Run(nil)
return nil
},
}
type signT struct {
cli.Helper
ContentFile string `cli:"c,content" usage:"path to the content to be signed"`
SignatureFile string `cli:"s,signature" usage:"path to the signature (will be created if does not exist)"`
IsDetached bool `cli:"a,attach" usage:"if false, the content will NOT be included in the signature file. If true, the content will be included, resulting in a larger file"`
}
var sign = &cli.Command{
Name: "sign",
Desc: "Signs a file using a digital certificate",
Argv: func() interface{} { return new(signT) },
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*signT)
ctx.String("Hello, sign command, I am %s %+v\n", argv.ContentFile, argv.IsDetached)
return nil
},
}
type joinSigsT struct {
cli.Helper
Name string `cli:"name" usage:"your name"`
}
var joinSigs = &cli.Command{
Name: "join",
Desc: "Join multiple signature files into one",
Argv: func() interface{} { return new(joinSigsT) },
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*joinSigsT)
ctx.String("Hello, verify command, I am %s\n", argv.Name)
return nil
},
}
type verifyT struct {
cli.Helper
Name string `cli:"name" usage:"your name"`
}
var verify = &cli.Command{
Name: "verify",
Desc: "Verifies if a signature is valid",
Argv: func() interface{} { return new(verifyT) },
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*verifyT)
ctx.String("Hello, verify command, I am %s\n", argv.Name)
return nil
},
}
var gen = &cli.Command{
Name: "gen",
Desc: "generates a new testing certificate",
Argv: func() interface{} { return new(genT) },
Fn: GenFunc,
}
func main() {
root := cli.Root(root,
cli.Tree(help),
cli.Tree(gen),
cli.Tree(sign),
cli.Tree(verify),
cli.Tree(joinSigs),
)
clix.InstallBashCompletion(root)
if err := root.Run(os.Args[1:]); err != nil {
red := "\033[1;91m"
reset := "\033[0m"
fmt.Fprintf(os.Stderr, "%sERR: %s%s\n", red, reset, err)
os.Exit(1)
}
}