diff options
-rw-r--r-- | tpl/crypto/crypto.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tpl/crypto/crypto.go b/tpl/crypto/crypto.go index e6e67e64b..42b420d59 100644 --- a/tpl/crypto/crypto.go +++ b/tpl/crypto/crypto.go @@ -23,6 +23,7 @@ import ( "encoding/hex" "fmt" "hash" + "hash/fnv" "github.com/spf13/cast" ) @@ -68,6 +69,17 @@ func (ns *Namespace) SHA256(in any) (string, error) { return hex.EncodeToString(hash[:]), nil } +// FNV32a hashes using fnv32a algorithm +func (ns *Namespace) FNV32a(in any) (int, error) { + conv, err := cast.ToStringE(in) + if err != nil { + return 0, err + } + algorithm := fnv.New32a() + algorithm.Write([]byte(conv)) + return int(algorithm.Sum32()), nil +} + // HMAC returns a cryptographic hash that uses a key to sign a message. func (ns *Namespace) HMAC(h any, k any, m any, e ...any) (string, error) { ha, err := cast.ToStringE(h) |