Skip to content

Commit

Permalink
Merge pull request #1 from r3v4-onbloc/feature/sha1-sum
Browse files Browse the repository at this point in the history
Feature/sha1 sum
  • Loading branch information
r3v4s authored Feb 7, 2023
2 parents 7ae9b59 + f55b6cd commit 62e3d0a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
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(s string) []byte {
return isha1.Sum(s)
}
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(
"s", "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

0 comments on commit 62e3d0a

Please sign in to comment.