Use io.ReadFull to read from random source.

This commit is contained in:
Dmitry Chestnykh 2011-04-05 21:52:50 +02:00
parent 6c4e68eee9
commit e810e021c7

View File

@ -16,6 +16,7 @@
package uniuri
import "crypto/rand"
import "io"
const (
// Standard length of uniuri string to achive ~95 bits of entropy.
@ -44,7 +45,7 @@ func NewLen(length int) string {
// of the provided byte slice of allowed characters (maximum 256).
func NewLenChars(length int, chars []byte) string {
b := make([]byte, length)
if _, err := rand.Read(b); err != nil {
if _, err := io.ReadFull(rand.Reader, b); err != nil {
panic("error reading from random source: " + err.String())
}
alen := byte(len(chars))