ksuid
ksuid copied to clipboard
Is there a regex pattern to validate the ksuid ?
KSUID textual representations are base62, so anything regex that checks for the 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
character set should work.
A quick stab at it:
func IsValidKsuid(str string) bool {
re := regexp.MustCompile("^[a-zA-Z0-9]{27}$")
return re.MatchString(str)
}
The KSUID is essentially a hash, so other than @alexpop's length + alphabet check, I don't think you can "prove" it's a valid ksuid using something like a checksum. However, you can run it through ksuid -f inspect
at the command line or using the library. This should prove it's actually a KSUID, not just any random 27-character string.