-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (56 loc) · 1.17 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
package main
import (
"fmt"
"log"
"os"
"github.com/t1anchen/gogmlib/sm3"
"github.com/t1anchen/gogmlib/utils"
"github.com/urfave/cli"
)
// VERSION 主程序的版本
const VERSION = "1.0.0"
func main() {
app := cli.NewApp()
app.Name = "gogmlib"
app.Version = VERSION
app.Commands = []cli.Command{
{
Name: "sm2",
Subcommands: []cli.Command{
{
Name: "encrypt",
Usage: "使用 sm2 加密",
Action: func(c *cli.Context) error {
fmt.Println("new task template: ", c.Args().First())
return nil
},
},
},
},
{
Name: "sm3",
Subcommands: []cli.Command{
{
Name: "compute",
Usage: "使用 sm3 哈希值计算",
Action: func(c *cli.Context) error {
if len(c.Args()) < 1 {
msgBuf := utils.ReadBytesFromStdinToBuffer()
fmt.Printf("%s *stdin\n", sm3.NewContext().ComputeFromBytes(msgBuf.Bytes()).ToHexString())
} else {
for _, v := range c.Args() {
hashStr := sm3.NewContext().ComputeFromString(v).ToHexString()
fmt.Printf("%s *%s\n", hashStr, v)
}
}
return nil
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}