1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 07:28:20 +08:00

global hash func

This commit is contained in:
Juan Batiz-Benet
2014-07-05 15:13:49 -07:00
parent 56b3dafbd7
commit 61ac7191c4
2 changed files with 7 additions and 1 deletions

View File

@ -72,7 +72,7 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return nil, err
}
return mh.Sum(b, mh.SHA2_256, -1)
return u.Hash(b)
}
func (n *Node) Key() (u.Key, error) {

View File

@ -2,6 +2,7 @@ package util
import (
"fmt"
mh "github.com/jbenet/go-multihash"
"os"
)
@ -11,6 +12,11 @@ var NotImplementedError = fmt.Errorf("Error: not implemented yet.")
// a Key for maps. It's a string (rep of a multihash).
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.
func PErr(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)