dex/pkg/crypto/rand.go
Giulio Iotti 472e4a02a4 *: Remove unnecessary else statements
Whenever it makes the code easier to follow, use early return to
avoid else statements.
2015-09-04 22:45:32 +03:00

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