/
validate.go
29 lines (24 loc) · 831 Bytes
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package hashes
import (
"regexp"
)
// ValidateMD5 returns true if the specified string is a valid MD5 hash.
func ValidateMD5(target string) bool {
rxp := regexp.MustCompile(`[a-fA-F0-9]{32}`)
return rxp.MatchString(target)
}
// ValidateSHA1 returns true if the specified string is a valid SHA1 hash.
func ValidateSHA1(target string) bool {
rxp := regexp.MustCompile(`[a-fA-F0-9]{40}`)
return rxp.MatchString(target)
}
// ValidateSHA256 returns true if the specified string is a valid SHA256 hash.
func ValidateSHA256(target string) bool {
rxp := regexp.MustCompile(`[a-fA-F0-9]{64}`)
return rxp.MatchString(target)
}
// ValidateSHA512 returns true if the specified string is a valid SHA512 hash.
func ValidateSHA512(target string) bool {
rxp := regexp.MustCompile(`[a-fA-F0-9]{128}`)
return rxp.MatchString(target)
}