Avoid generating an identifer which starts with a number because it may be used as a SAML's ID attribute

This commit is contained in:
Kazumasa Kohtaka 2017-07-06 21:28:48 +09:00
parent 6f2af269a1
commit cc314690f4

View file

@ -30,8 +30,8 @@ func NewID() string {
if _, err := io.ReadFull(rand.Reader, buff); err != nil { if _, err := io.ReadFull(rand.Reader, buff); err != nil {
panic(err) panic(err)
} }
// Trim padding // Avoid the identifier to begin with number and trim padding
return strings.TrimRight(encoding.EncodeToString(buff), "=") return string(buff[0]%26+'a') + strings.TrimRight(encoding.EncodeToString(buff[1:]), "=")
} }
// GCResult returns the number of objects deleted by garbage collection. // GCResult returns the number of objects deleted by garbage collection.