github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/bfs/hash.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package bfs 4 5 import ( 6 "fmt" 7 stringutil "github.com/iwind/TeaGo/utils/string" 8 ) 9 10 var HashLen = 32 11 12 // CheckHash check hash string format 13 func CheckHash(hash string) bool { 14 if len(hash) != HashLen { 15 return false 16 } 17 18 for _, b := range hash { 19 if !((b >= '0' && b <= '9') || (b >= 'a' && b <= 'f')) { 20 return false 21 } 22 } 23 24 return true 25 } 26 27 func CheckHashErr(hash string) error { 28 if CheckHash(hash) { 29 return nil 30 } 31 return fmt.Errorf("check hash '%s' failed: %w", hash, ErrInvalidHash) 32 } 33 34 func Hash(s string) string { 35 return stringutil.Md5(s) 36 }