fix: code challenge

This commit is contained in:
Livio Amstutz 2020-02-28 18:07:01 +01:00
parent 7f486a54c4
commit c3169868d8
3 changed files with 8 additions and 4 deletions

View file

@ -23,8 +23,12 @@ func GetHashAlgorithm(sigAlgorithm jose.SignatureAlgorithm) (hash.Hash, error) {
}
}
func HashString(hash hash.Hash, s string) string {
func HashString(hash hash.Hash, s string, firstHalf bool) string {
hash.Write([]byte(s)) // hash documents that Write will never return an error
sum := hash.Sum(nil)[:hash.Size()/2]
size = hash.Size()
if firstHalf {
size = size / 2
}
sum := hash.Sum(nil)[:size]
return base64.RawURLEncoding.EncodeToString(sum)
}