diff --git a/metainfo/hash.go b/metainfo/hash.go index 58c5b7cc..1c0a0ff8 100644 --- a/metainfo/hash.go +++ b/metainfo/hash.go @@ -1,6 +1,7 @@ package metainfo import ( + "crypto/sha1" "encoding/hex" "fmt" ) @@ -34,3 +35,10 @@ func (h *Hash) FromHexString(s string) (err error) { } return } + +func HashBytes(b []byte) (ret Hash) { + hasher := sha1.New() + hasher.Write(b) + copy(ret[:], hasher.Sum(nil)) + return +}