mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 02:46:30 +02:00
29 lines
712 B
Go
29 lines
712 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 any) 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 any) (uint64, error) {
|
|
opts := &hashstructure.HashOptions{
|
|
Hasher: xxhash.New(),
|
|
}
|
|
return hashstructure.Hash(v, hashstructure.FormatV2, opts)
|
|
}
|