Fix md5 string length
Some checks failed
Deploy / build (push) Failing after 10m4s

This commit is contained in:
Paul-Christian Volkmer 2024-02-20 20:01:51 +01:00
parent 8e5ca646d0
commit 11cfa5a1eb

View File

@ -7,6 +7,7 @@ import (
"image/color" "image/color"
"image/draw" "image/draw"
"regexp" "regexp"
"strings"
) )
type IconGenerator interface { type IconGenerator interface {
@ -16,14 +17,14 @@ type IconGenerator interface {
func HashBytes(id string) [16]byte { func HashBytes(id string) [16]byte {
hash := [16]byte{} hash := [16]byte{}
md5RegExp := regexp.MustCompile("[a-f0-9]{32}") md5RegExp := regexp.MustCompile("[a-f0-9]{32}")
if len(id) == 16 && md5RegExp.MatchString(id) { if len(id) == 32 && md5RegExp.MatchString(strings.ToLower(id)) {
dec, _ := hex.DecodeString(id) dec, _ := hex.DecodeString(id)
for idx, b := range dec { for idx, b := range dec {
print(idx) print(idx)
hash[idx] = b hash[idx] = b
} }
} else { } else {
hash = md5.Sum([]byte(id)) hash = md5.Sum([]byte(strings.ToLower(id)))
} }
return hash return hash
} }