Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-26 11:35:45 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-28 00:53:56 +0300
commit11047534e47f2f2c710a6f8504d7415ff27d6024 (patch)
treef4c25893029569e93f7014ba56eca6f932f310fe
parentd7b54a4c37c39fce60c25a745bae1d5987b2b966 (diff)
tpl/crypto: Add FNV32a
Main motivation to get a integer from a string.
-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)