pomerium/internal/hashutil/hashutil.go
bobby 652e8bb3d3
deps: update hashstructure v2 (#1632)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
2020-11-30 16:53:21 -08:00

29 lines
728 B
Go

// Package hashutil provides NON-CRYPTOGRAPHIC utility functions for hashing.
//
// http://cyan4973.github.io/xxHash/
package hashutil
import (
"github.com/cespare/xxhash/v2"
"github.com/mitchellh/hashstructure/v2"
)
// MustHash returns the xxhash of an arbitrary value or struct. Returns 0
// on error.
// NOT SUITABLE FOR CRYTOGRAPHIC HASHING.
func MustHash(v interface{}) uint64 {
hash, err := Hash(v)
if err != nil {
hash = 0
}
return hash
}
// Hash returns the xxhash of an arbitrary value or struct.
// NOT SUITABLE FOR CRYTOGRAPHIC HASHING.
func Hash(v interface{}) (uint64, error) {
opts := &hashstructure.HashOptions{
Hasher: xxhash.New(),
}
return hashstructure.Hash(v, hashstructure.FormatV2, opts)
}