ksuid icon indicating copy to clipboard operation
ksuid copied to clipboard

Is there a regex pattern to validate the ksuid ?

Open lanpar opened this issue 6 years ago • 3 comments

lanpar avatar Aug 23 '18 18:08 lanpar

KSUID textual representations are base62, so anything regex that checks for the 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz character set should work.

achille-roussel avatar Aug 23 '18 19:08 achille-roussel

A quick stab at it:

func IsValidKsuid(str string) bool {
	re := regexp.MustCompile("^[a-zA-Z0-9]{27}$")
	return re.MatchString(str)
}

alexpop avatar Dec 07 '20 06:12 alexpop

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.

ShawnMilo avatar Dec 07 '20 16:12 ShawnMilo