This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/pkg/crypto/rand.go
2015-08-18 11:26:57 -07:00

18 lines
284 B
Go

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
} else if n != got {
return nil, errors.New("unable to generate enough random data")
}
return b, nil
}