dex/pkg/crypto/rand.go

19 lines
280 B
Go
Raw Normal View History

2015-08-18 05:57:27 +05:30
package crypto
import (
"crypto/rand"
"errors"
)
func RandBytes(n int) ([]byte, error) {
b := make([]byte, n)
got, err := rand.Read(b)
if err != nil {
return nil, err
}
if n != got {
2015-08-18 05:57:27 +05:30
return nil, errors.New("unable to generate enough random data")
}
return b, nil
}