-
Notifications
You must be signed in to change notification settings - Fork 22
/
with.go
102 lines (76 loc) · 1.67 KB
/
with.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
package sm2
import (
"github.com/deatil/go-cryptobin/tool"
"github.com/deatil/go-cryptobin/gm/sm2"
)
// 设置 PrivateKey
func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2 {
this.privateKey = data
return this
}
// 设置 PublicKey
func (this SM2) WithPublicKey(data *sm2.PublicKey) SM2 {
this.publicKey = data
return this
}
// 设置 mode
func (this SM2) WithMode(data sm2.Mode) SM2 {
this.mode = data
return this
}
// 设置 mode
// C1C3C2 = 0 | C1C2C3 = 1
func (this SM2) SetMode(data string) SM2 {
switch data {
case "C1C3C2":
this.mode = sm2.C1C3C2
case "C1C2C3":
this.mode = sm2.C1C2C3
}
return this
}
// 设置 data
func (this SM2) WithData(data []byte) SM2 {
this.data = data
return this
}
// 设置 parsedData
func (this SM2) WithParsedData(data []byte) SM2 {
this.parsedData = data
return this
}
// 设置 hash 类型
func (this SM2) WithSignHash(data HashFunc) SM2 {
this.signHash = data
return this
}
// 设置 hash 类型
// 可用参数可查看 Hash 结构体数据
func (this SM2) SetSignHash(data string) SM2 {
hash, err := tool.GetHash(data)
if err != nil {
return this.AppendError(err)
}
this.signHash = hash
return this
}
// 设置 uid
func (this SM2) WithUID(data []byte) SM2 {
this.uid = data
return this
}
// 设置 uid
func (this SM2) SetUID(data string) SM2 {
this.uid = []byte(data)
return this
}
// 设置 verify
func (this SM2) WithVerify(data bool) SM2 {
this.verify = data
return this
}
// 设置错误
func (this SM2) WithErrors(errs []error) SM2 {
this.Errors = errs
return this
}