Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/sha1-sum #2

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/gnolang/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var stdlibWhitelist = []string{
"encoding/base64",
"encoding/binary",
"encoding/xml",
"encoding/hex",
"errors",
"flag",
"fmt",
Expand Down
19 changes: 19 additions & 0 deletions stdlibs/crypto/sha1/sha1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package sha1 implements the SHA-1 hash algorithm as defined in RFC 3174.
//
// SHA-1 is cryptographically broken and should not be used for secure
// applications.

package sha1

import (
isha1 "internal/crypto/sha1"
)

// Sum returns the SHA-1 checksum of the data.
func Sum(data string) []byte {
return isha1.Sum(data)
}
1 change: 1 addition & 0 deletions stdlibs/internal/crypto/sha1/sha1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package sha1
15 changes: 15 additions & 0 deletions stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stdlibs

import (
"crypto/sha1"
"math"
"reflect"
"strconv"
Expand All @@ -20,6 +21,20 @@ func InjectNativeMappings(store gno.Store) {

func InjectPackage(store gno.Store, pn *gno.PackageNode) {
switch pn.PkgPath {
case "internal/crypto/sha1":
pn.DefineNative("Sum",
gno.Flds(
"data", "string",
),
gno.Flds(
"bs", "[]byte",
),
func(m *gno.Machine) {
arg0 := m.LastBlock().GetParams1().TV
hash := sha1.Sum([]byte(arg0.GetString()))
m.PushValue(typedByteArray(20, m.Alloc.NewArrayFromData(hash[:])))
},
)
case "internal/math":
pn.DefineNative("Float32bits",
gno.Flds( // params
Expand Down