-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsha1.go
43 lines (39 loc) · 849 Bytes
/
sha1.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
package sha1
import (
"crypto/sha1"
luadoc "github.com/mangalorg/gopher-luadoc"
lua "github.com/yuin/gopher-lua"
)
func Lib() *luadoc.Lib {
return &luadoc.Lib{
Name: "sha1",
Description: "SHA1 cryptographic hash function.",
Funcs: []*luadoc.Func{
{
Name: "sum",
Description: "Returns the SHA1 hash of the given string.",
Value: sum,
Params: []*luadoc.Param{
{
Name: "value",
Description: "The string to hash.",
Type: luadoc.String,
},
},
Returns: []*luadoc.Param{
{
Name: "hash",
Description: "The SHA1 hash of the given string.",
Type: luadoc.String,
},
},
},
},
}
}
func sum(L *lua.LState) int {
value := L.CheckString(1)
s := sha1.Sum([]byte(value))
L.Push(lua.LString(s[:]))
return 1
}