-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
50 lines (45 loc) · 934 Bytes
/
helper.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
package helper
import (
"crypto"
"errors"
"strings"
)
func JoinAsError(msg []string) error {
if len(msg) > 0 {
return errors.New(strings.Join(msg, "\n"))
}
return nil
}
func JoinErrors(errs []error) error {
msgs := make([]string, 0, len(errs))
for _, err := range errs {
if err != nil {
msgs = append(msgs, err.Error())
}
}
return JoinAsError(msgs)
}
func GetHashFunctionByLowerCaseName(hashName string) (crypto.Hash, error) {
switch hashName {
case "md4":
return crypto.MD4, nil
case "md5":
return crypto.MD5, nil
case "sha1":
return crypto.SHA1, nil
case "sha224":
return crypto.SHA224, nil
case "sha256":
return crypto.SHA256, nil
case "sha384":
return crypto.SHA384, nil
case "sha512":
return crypto.SHA512, nil
case "md5sha1":
return crypto.MD5SHA1, nil
case "ripemd160":
return crypto.RIPEMD160, nil
default:
return 0, errors.New("unknown lowercase hash " + hashName)
}
}