-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_use.go
56 lines (43 loc) · 1.05 KB
/
hash_use.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
package hash
import (
"fmt"
"hash"
)
// 接口
type IHash interface {
// Sum [输入内容, sum输入值, 其他配置]
Sum([]byte, []byte, ...map[string]any) ([]byte, error)
// New
New(...map[string]any) (hash.Hash, error)
}
// 使用
var UseHash = NewDataSet[string, IHash]()
// 获取方式
func getHash(name string) (IHash, error) {
if !UseHash.Has(name) {
err := fmt.Errorf("Hash: Hash type [%s] is error.", name)
return nil, err
}
newHash := UseHash.Get(name)
return newHash(), nil
}
// Sum
func (this Hash) SumBy(name string, in []byte, cfg ...map[string]any) Hash {
newHash, err := getHash(name)
if err != nil {
this.Error = err
return this
}
this.data, this.Error = newHash.Sum(this.data, in, cfg...)
return this
}
// New
func (this Hash) NewBy(name string, cfg ...map[string]any) Hash {
newHash, err := getHash(name)
if err != nil {
this.Error = err
return this
}
this.hash, this.Error = newHash.New(cfg...)
return this
}