mirror of
https://github.com/pcvolkmer/idicon.git
synced 2025-07-01 19:32:54 +00:00
Only use id as hash if it is 16 bytes md5 hex string
This commit is contained in:
@ -16,13 +16,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 !md5RegExp.Match([]byte(id)) {
|
if len(id) == 16 && md5RegExp.MatchString(id) {
|
||||||
hash = md5.Sum([]byte(id))
|
|
||||||
} else {
|
|
||||||
dec, _ := hex.DecodeString(id)
|
dec, _ := hex.DecodeString(id)
|
||||||
for idx, b := range dec {
|
for idx, b := range dec {
|
||||||
|
print(idx)
|
||||||
hash[idx] = b
|
hash[idx] = b
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
hash = md5.Sum([]byte(id))
|
||||||
}
|
}
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user