github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/actions/lua/crypto/sha256/sha256.go (about) 1 package sha256 2 3 import ( 4 "crypto/sha256" 5 6 "github.com/Shopify/go-lua" 7 ) 8 9 func Open(l *lua.State) { 10 open := func(l *lua.State) int { 11 lua.NewLibrary(l, library) 12 return 1 13 } 14 lua.Require(l, "crypto/sha256", open, false) 15 l.Pop(1) 16 } 17 18 var library = []lua.RegistryFunction{ 19 {Name: "digest", Function: digest}, 20 } 21 22 func digest(l *lua.State) int { 23 message := lua.CheckString(l, 1) 24 25 h := sha256.New() 26 h.Write([]byte(message)) 27 28 l.PushString(string(h.Sum(nil))) 29 return 1 30 }