From c2de3672e5b50aba198c2cf22c0ac08f6bf2618f Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Sat, 14 Sep 2019 13:39:40 +0200 Subject: [PATCH] Add IsSupportedDigestAlgorithm --- digest.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/digest.go b/digest.go index 9aaeb8c..b5c6242 100644 --- a/digest.go +++ b/digest.go @@ -22,6 +22,14 @@ var digestToDef = map[DigestAlgorithm]crypto.Hash{ DigestSha512: crypto.SHA512, } +// IsSupportedDigestAlgorithm returns true if hte string is supported by this +// library, is not a hash known to be weak, and is supported by the hardware. +func IsSupportedDigestAlgorithm(algo string) bool { + uc := DigestAlgorithm(strings.ToUpper(algo)) + c, ok := digestToDef[uc] + return ok && c.Available() +} + func getHash(alg DigestAlgorithm) (h hash.Hash, toUse DigestAlgorithm, err error) { upper := DigestAlgorithm(strings.ToUpper(string(alg))) c, ok := digestToDef[upper]