From 2cf2c15def0b83b81538645e8935b3c4e8308b96 Mon Sep 17 00:00:00 2001 From: Paul TREHIOU Date: Sat, 23 Dec 2017 19:03:14 +0100 Subject: [PATCH] Case insensitive algorithm match --- totp.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/totp.go b/totp.go index 10a2876..c3d6f3f 100644 --- a/totp.go +++ b/totp.go @@ -123,12 +123,11 @@ func totpFromURL(u *url.URL) (*TOTP, string, error) { var algo = crypto.SHA1 if algorithm := v.Get("algorithm"); algorithm != "" { - switch { - case algorithm == "SHA256": + if strings.EqualFold(algorithm, "SHA256") { algo = crypto.SHA256 - case algorithm == "SHA512": + } else if strings.EqualFold(algorithm, "SHA512") { algo = crypto.SHA512 - case algorithm != "SHA1": + } else if !strings.EqualFold(algorithm, "SHA1") { return nil, "", ErrInvalidAlgo } }