pomerium/internal/hashutil/hashutil.go
Bobby DeSimone 666fd6aa35 authenticate: save oauth2 tokens to cache (#698)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
2020-05-18 17:10:10 -04:00

22 lines
531 B
Go

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