-
Notifications
You must be signed in to change notification settings - Fork 5
/
md5_exports.go
71 lines (58 loc) · 1.27 KB
/
md5_exports.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
package md5
import (
"crypto/md5"
"encoding/hex"
"io"
)
// -----------------------------------------------------------------------------
// Hash returns md5 sum of (sep, args...) serialization.
//
func Hash(sep interface{}, args ...interface{}) string {
h := md5.New()
var bsep []byte
switch v := sep.(type) {
case []byte:
bsep = v
case string:
bsep = []byte(v)
default:
panic("md5.Hash: invalid argument type, require []byte or string")
}
for i, arg := range args {
if i > 0 {
h.Write(bsep)
}
switch v := arg.(type) {
case []byte:
h.Write(v)
case string:
io.WriteString(h, v)
case error:
default:
panic("md5.Hash: invalid argument type, require []byte or string")
}
}
return hex.EncodeToString(h.Sum(nil))
}
// Sumstr is hex.EncodeToString(md5.Sum(b)).
//
func Sumstr(b []byte) string {
v := md5.Sum(b)
return hex.EncodeToString(v[:])
}
// Exports is the export table of this module.
//
var Exports = map[string]interface{}{
"_name": "crypto/md5",
"new": md5.New,
"sum": md5.Sum,
"sumstr": Sumstr,
"hash": Hash,
"New": md5.New,
"Sum": md5.Sum,
"Sumstr": Sumstr,
"Hash": Hash,
"BlockSize": md5.BlockSize,
"Size": md5.Size,
}
// -----------------------------------------------------------------------------