util: correctly truncate randomurl string

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2025-01-13 11:48:41 +01:00
parent 78a70b455d
commit 01fccbc3e8
No known key found for this signature in database

View file

@ -32,7 +32,8 @@ func GenerateRandomBytes(n int) ([]byte, error) {
func GenerateRandomStringURLSafe(n int) (string, error) {
b, err := GenerateRandomBytes(n)
return base64.RawURLEncoding.EncodeToString(b), err
uenc := base64.RawURLEncoding.EncodeToString(b)
return uenc[:n], err
}
// GenerateRandomStringDNSSafe returns a DNS-safe