aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2022-04-26 10:35:45 +0200
committerBjørn Erik Pedersen <[email protected]>2022-04-27 23:53:56 +0200
commit11047534e47f2f2c710a6f8504d7415ff27d6024 (patch)
treef4c25893029569e93f7014ba56eca6f932f310fe /tpl
parentd7b54a4c37c39fce60c25a745bae1d5987b2b966 (diff)
downloadhugo-11047534e47f2f2c710a6f8504d7415ff27d6024.tar.gz
hugo-11047534e47f2f2c710a6f8504d7415ff27d6024.zip
tpl/crypto: Add FNV32a
Main motivation to get a integer from a string.
Diffstat (limited to 'tpl')
-rw-r--r--tpl/crypto/crypto.go12
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)