feat: initial implementation

This commit is contained in:
2022-02-14 17:48:13 +00:00
commit 7b743b7805
5 changed files with 155 additions and 0 deletions

28
rand.go Normal file
View File

@@ -0,0 +1,28 @@
package gomockctx
import (
"crypto/rand"
"math/big"
)
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"0123456789"
// randString returns a cryptographically secure random string of alphanumeric
// characters of n length.
//
// Borrowed from github.com/jimeh/rands package.
func randString(n int) (string, error) {
l := big.NewInt(int64(len(alphabet)))
b := make([]byte, n)
for i := 0; i < n; i++ {
index, err := rand.Int(rand.Reader, l)
if err != nil {
return "", err
}
b[i] = alphabet[index.Int64()]
}
return string(b), nil
}