1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:54:46 -07:00

crypto/rand: make Read use io.ReadFull

Fixes #6084

R=golang-dev, rsc, dave
CC=golang-dev
https://golang.org/cl/13523044
This commit is contained in:
Brad Fitzpatrick 2013-09-06 12:00:27 -07:00
parent a3834a2e8a
commit c327e82ddb
2 changed files with 6 additions and 4 deletions

View File

@ -8,7 +8,6 @@ import (
"bytes"
"crypto/rand"
"fmt"
"io"
)
// This example reads 10 cryptographically secure pseudorandom numbers from
@ -16,7 +15,7 @@ import (
func ExampleRead() {
c := 10
b := make([]byte, c)
_, err := io.ReadFull(rand.Reader, b)
_, err := rand.Read(b)
if err != nil {
fmt.Println("error:", err)
return

View File

@ -14,5 +14,8 @@ import "io"
// On Windows systems, Reader uses the CryptGenRandom API.
var Reader io.Reader
// Read is a helper function that calls Reader.Read.
func Read(b []byte) (n int, err error) { return Reader.Read(b) }
// Read is a helper function that calls Reader.Read using io.ReadFull.
// On return, n == len(b) if and only if err == nil.
func Read(b []byte) (n int, err error) {
return io.ReadFull(Reader, b)
}