Skip to content

Commit 965cda0

Browse files
committed
fixed
1 parent 0a95154 commit 965cda0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+507
-445
lines changed

cryptobin/crypto/encrypt.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (this Cryptobin) Encrypt() Cryptobin {
4141
})
4242

4343
if err != nil {
44-
return this.AppendError(err).triggerError()
44+
return this.AppendTriggerError(err)
4545
}
4646

4747
return this
@@ -52,17 +52,17 @@ func (this Cryptobin) encrypt() Cryptobin {
5252
// Encrypt
5353
newEncrypt, err := getEncrypt(this.multiple)
5454
if err != nil {
55-
return this.AppendError(err).triggerError()
55+
return this.AppendTriggerError(err)
5656
}
5757

5858
dst, err := newEncrypt.Encrypt(this.data, NewConfig(this))
5959
if err != nil {
60-
return this.AppendError(err).triggerError()
60+
return this.AppendTriggerError(err)
6161
}
6262

6363
this.parsedData = dst
6464

65-
return this.triggerError()
65+
return this.TriggerError()
6666
}
6767

6868
// 解密
@@ -73,7 +73,7 @@ func (this Cryptobin) Decrypt() Cryptobin {
7373
})
7474

7575
if err != nil {
76-
return this.AppendError(err).triggerError()
76+
return this.AppendTriggerError(err)
7777
}
7878

7979
return this
@@ -84,17 +84,17 @@ func (this Cryptobin) decrypt() Cryptobin {
8484
// Encrypt
8585
newEncrypt, err := getEncrypt(this.multiple)
8686
if err != nil {
87-
return this.AppendError(err).triggerError()
87+
return this.AppendTriggerError(err)
8888
}
8989

9090
dst, err := newEncrypt.Decrypt(this.data, NewConfig(this))
9191
if err != nil {
92-
return this.AppendError(err).triggerError()
92+
return this.AppendTriggerError(err)
9393
}
9494

9595
this.parsedData = dst
9696

97-
return this.triggerError()
97+
return this.TriggerError()
9898
}
9999

100100
// ====================
@@ -103,11 +103,11 @@ func (this Cryptobin) decrypt() Cryptobin {
103103
// Func Encrypt
104104
func (this Cryptobin) FuncEncrypt(fn func(Cryptobin) Cryptobin) Cryptobin {
105105
err := recover.Recover(func() {
106-
this = fn(this).triggerError()
106+
this = fn(this).TriggerError()
107107
})
108108

109109
if err != nil {
110-
return this.AppendError(err).triggerError()
110+
return this.AppendTriggerError(err)
111111
}
112112

113113
return this
@@ -117,11 +117,11 @@ func (this Cryptobin) FuncEncrypt(fn func(Cryptobin) Cryptobin) Cryptobin {
117117
// Func Decrypt
118118
func (this Cryptobin) FuncDecrypt(fn func(Cryptobin) Cryptobin) Cryptobin {
119119
err := recover.Recover(func() {
120-
this = fn(this).triggerError()
120+
this = fn(this).TriggerError()
121121
})
122122

123123
if err != nil {
124-
return this.AppendError(err).triggerError()
124+
return this.AppendTriggerError(err)
125125
}
126126

127127
return this

cryptobin/crypto/error.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ func (this Cryptobin) AppendError(err ...error) Cryptobin {
1212
return this
1313
}
1414

15+
// Append Trigger Error
16+
func (this Cryptobin) AppendTriggerError(err ...error) Cryptobin {
17+
return this.AppendError(err...).TriggerError()
18+
}
19+
1520
// 获取错误
1621
// get error
1722
func (this Cryptobin) Error() error {

cryptobin/crypto/on.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (this Cryptobin) OnError(fn ErrorFunc) Cryptobin {
1616

1717
// 触发错误事件
1818
// trigger Error
19-
func (this Cryptobin) triggerError() Cryptobin {
19+
func (this Cryptobin) TriggerError() Cryptobin {
2020
this.errEvent.Trigger(this.Errors)
2121

2222
return this

cryptobin/dsa/check.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dsa
22

3-
// 检测公钥私钥是否匹配
3+
// Check KeyPair
44
func (this DSA) CheckKeyPair() bool {
5-
// 私钥导出的公钥
5+
// from private key
66
pubKeyFromPriKey := this.MakePublicKey().
77
CreatePublicKey().
88
ToKeyString()
99

10-
// 公钥数据
10+
// pubkey data
1111
pubKeyFromPubKey := this.CreatePublicKey().ToKeyString()
1212

1313
if pubKeyFromPriKey == "" || pubKeyFromPubKey == "" {

cryptobin/dsa/create.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@ import (
1111
)
1212

1313
type (
14-
// 配置
14+
// Options
1515
Opts = pkcs8.Opts
16-
// PBKDF2 配置
16+
// PBKDF2 Options
1717
PBKDF2Opts = pkcs8.PBKDF2Opts
18-
// Scrypt 配置
18+
// Scrypt Options
1919
ScryptOpts = pkcs8.ScryptOpts
2020
)
2121

2222
var (
23-
// 获取 Cipher 类型
23+
// Get cipher from name
2424
GetCipherFromName = pkcs8.GetCipherFromName
25-
// 获取 hash 类型
25+
// Get hash from name
2626
GetHashFromName = pkcs8.GetHashFromName
2727
)
2828

29-
// 生成私钥 pem 数据
29+
// Create PrivateKey PEM data
3030
// dsa := New().GenerateKey("L2048N256")
3131
// priKey := dsa.CreatePrivateKey().ToKeyString()
3232
func (this DSA) CreatePrivateKey() DSA {
3333
return this.CreatePKCS1PrivateKey()
3434
}
3535

36-
// 生成私钥带密码 pem 数据
36+
// Create PrivateKey PEM data with password
3737
// CreatePrivateKeyWithPassword("123", "AES256CBC")
3838
// PEMCipher: DESCBC | DESEDE3CBC | AES128CBC | AES192CBC | AES256CBC
3939
func (this DSA) CreatePrivateKeyWithPassword(password string, opts ...string) DSA {
4040
return this.CreatePKCS1PrivateKeyWithPassword(password, opts...)
4141
}
4242

43-
// 生成公钥 pem 数据
43+
// Create PublicKey PEM data
4444
func (this DSA) CreatePublicKey() DSA {
4545
return this.CreatePKCS1PublicKey()
4646
}
4747

4848
// ==========
4949

50-
// 生成 pkcs1 私钥 pem 数据
50+
// Create PKCS1 PrivateKey PEM data
5151
func (this DSA) CreatePKCS1PrivateKey() DSA {
5252
if this.privateKey == nil {
5353
err := errors.New("go-cryptobin/dsa: privateKey empty.")
@@ -69,7 +69,7 @@ func (this DSA) CreatePKCS1PrivateKey() DSA {
6969
return this
7070
}
7171

72-
// 生成 pkcs1 私钥带密码 pem 数据
72+
// Create PKCS1 PrivateKey PEM data with password
7373
// CreatePKCS1PrivateKeyWithPassword("123", "AES256CBC")
7474
// PEMCipher: DESCBC | DESEDE3CBC | AES128CBC | AES192CBC | AES256CBC
7575
func (this DSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...string) DSA {
@@ -113,7 +113,7 @@ func (this DSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...strin
113113
return this
114114
}
115115

116-
// 生成 pkcs1 公钥 pem 数据
116+
// Create PKCS1 PublicKey PEM data
117117
func (this DSA) CreatePKCS1PublicKey() DSA {
118118
if this.publicKey == nil {
119119
err := errors.New("go-cryptobin/dsa: publicKey empty.")
@@ -137,7 +137,7 @@ func (this DSA) CreatePKCS1PublicKey() DSA {
137137

138138
// ==========
139139

140-
// 生成 pkcs8 私钥 pem 数据
140+
// Create PKCS8 PrivateKey PEM data
141141
func (this DSA) CreatePKCS8PrivateKey() DSA {
142142
if this.privateKey == nil {
143143
err := errors.New("go-cryptobin/dsa: privateKey empty.")
@@ -159,7 +159,7 @@ func (this DSA) CreatePKCS8PrivateKey() DSA {
159159
return this
160160
}
161161

162-
// 生成 PKCS8 私钥带密码 pem 数据
162+
// Create PKCS8 PrivateKey PEM data with password
163163
// CreatePKCS8PrivateKeyWithPassword("123", "AES256CBC", "SHA256")
164164
func (this DSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) DSA {
165165
if this.privateKey == nil {
@@ -195,7 +195,7 @@ func (this DSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any)
195195
return this
196196
}
197197

198-
// 生成公钥 pem 数据
198+
// Create PKCS8 PublicKey PEM data
199199
func (this DSA) CreatePKCS8PublicKey() DSA {
200200
if this.publicKey == nil {
201201
err := errors.New("go-cryptobin/dsa: publicKey empty.")
@@ -219,7 +219,7 @@ func (this DSA) CreatePKCS8PublicKey() DSA {
219219

220220
// ====================
221221

222-
// 生成私钥 xml 数据
222+
// Create PrivateKey XML data
223223
func (this DSA) CreateXMLPrivateKey() DSA {
224224
if this.privateKey == nil {
225225
err := errors.New("go-cryptobin/dsa: privateKey empty.")
@@ -236,7 +236,7 @@ func (this DSA) CreateXMLPrivateKey() DSA {
236236
return this
237237
}
238238

239-
// 生成公钥 xml 数据
239+
// Create PublicKey XML data
240240
func (this DSA) CreateXMLPublicKey() DSA {
241241
if this.publicKey == nil {
242242
err := errors.New("go-cryptobin/dsa: publicKey empty.")

cryptobin/dsa/dsa.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@ const (
2727
* @author deatil
2828
*/
2929
type DSA struct {
30-
// 私钥
30+
// PrivateKey
3131
privateKey *dsa.PrivateKey
3232

33-
// 公钥
33+
// PublicKey
3434
publicKey *dsa.PublicKey
3535

36-
// [私钥/公钥]数据
36+
// [PrivateKey/PublicKey]data
3737
keyData []byte
3838

39-
// 传入数据
39+
// input data
4040
data []byte
4141

42-
// 解析后的数据
42+
// parsed data
4343
parsedData []byte
4444

45-
// 签名验证类型
45+
// sign hash type
4646
signHash HashFunc
4747

48-
// 数据编码方式
48+
// encoding type
4949
encoding EncodingType
5050

51-
// 验证结果
51+
// verify data
5252
verify bool
5353

54-
// 错误
54+
// error list
5555
Errors []error
5656
}
5757

58-
// 构造函数
58+
// NewDSA
5959
func NewDSA() DSA {
6060
return DSA{
6161
signHash: sha256.New,
@@ -64,12 +64,12 @@ func NewDSA() DSA {
6464
}
6565
}
6666

67-
// 构造函数
67+
// New DSA
6868
func New() DSA {
6969
return NewDSA()
7070
}
7171

7272
var (
73-
// 默认
73+
// default New DSA
7474
defaultDSA = NewDSA()
7575
)

cryptobin/dsa/error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"github.com/deatil/go-cryptobin/tool/errors"
55
)
66

7-
// 添加错误
7+
// append error
88
func (this DSA) AppendError(err ...error) DSA {
99
this.Errors = append(this.Errors, err...)
1010

1111
return this
1212
}
1313

14-
// 获取错误
14+
// return error
1515
func (this DSA) Error() error {
1616
return errors.Join(this.Errors...)
1717
}

0 commit comments

Comments
 (0)