diff --git a/crypto.go b/crypto.go index 13a5cd5..75fe027 100644 --- a/crypto.go +++ b/crypto.go @@ -14,6 +14,7 @@ import ( "crypto/rsa" "crypto/sha1" "crypto/sha256" + "crypto/sha512" "crypto/x509" "crypto/x509/pkix" "encoding/asn1" @@ -36,6 +37,11 @@ import ( "golang.org/x/crypto/scrypt" ) +func sha512sum(input string) string { + hash := sha512.Sum512([]byte(input)) + return hex.EncodeToString(hash[:]) +} + func sha256sum(input string) string { hash := sha256.Sum256([]byte(input)) return hex.EncodeToString(hash[:]) diff --git a/crypto_test.go b/crypto_test.go index 449e7ff..5040fb9 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -26,6 +26,13 @@ var ( } ) +func TestSha512Sum(t *testing.T) { + tpl := `{{"abc" | sha512sum}}` + if err := runt(tpl, "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); err != nil { + t.Error(err) + } +} + func TestSha256Sum(t *testing.T) { tpl := `{{"abc" | sha256sum}}` if err := runt(tpl, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); err != nil { diff --git a/functions.go b/functions.go index 57fcec1..dafcb7f 100644 --- a/functions.go +++ b/functions.go @@ -159,6 +159,7 @@ var genericMap = map[string]interface{}{ "plural": plural, "sha1sum": sha1sum, "sha256sum": sha256sum, + "sha512sum": sha512sum, "adler32sum": adler32sum, "toString": strval,