package oidc import ( "crypto/rand" "fmt" "math/big" ) const base62Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // randomNonce returns an n-character base62 string from crypto/rand, used // for client_nonce. Deliberately not a dependency on // github.com/hashicorp/go-secure-stdlib/base62 — this is the same // crypto/rand-backed generation in about ten lines. func randomNonce(n int) string { b := make([]byte, n) max := big.NewInt(int64(len(base62Alphabet))) for i := range b { idx, err := rand.Int(rand.Reader, max) if err != nil { panic(fmt.Sprintf("oidc: crypto/rand unavailable: %v", err)) } b[i] = base62Alphabet[idx.Int64()] } return string(b) }