提交 61ac7191 作者: Juan Batiz-Benet

global hash func

上级 56b3dafb
...@@ -72,7 +72,7 @@ func (n *Node) Multihash() (mh.Multihash, error) { ...@@ -72,7 +72,7 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return nil, err return nil, err
} }
return mh.Sum(b, mh.SHA2_256, -1) return u.Hash(b)
} }
func (n *Node) Key() (u.Key, error) { func (n *Node) Key() (u.Key, error) {
......
...@@ -2,6 +2,7 @@ package util ...@@ -2,6 +2,7 @@ package util
import ( import (
"fmt" "fmt"
mh "github.com/jbenet/go-multihash"
"os" "os"
) )
...@@ -11,6 +12,11 @@ var NotImplementedError = fmt.Errorf("Error: not implemented yet.") ...@@ -11,6 +12,11 @@ var NotImplementedError = fmt.Errorf("Error: not implemented yet.")
// a Key for maps. It's a string (rep of a multihash). // a Key for maps. It's a string (rep of a multihash).
type Key string type Key string
// global hash function. uses multihash SHA2_256, 256 bits
func Hash(data []byte) (mh.Multihash, error) {
return mh.Sum(data, mh.SHA2_256, -1)
}
// Shorthand printing functions. // Shorthand printing functions.
func PErr(format string, a ...interface{}) { func PErr(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...) fmt.Fprintf(os.Stderr, format, a...)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论