Commit c327e82d authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

crypto/rand: make Read use io.ReadFull

Fixes #6084

R=golang-dev, rsc, dave
CC=golang-dev
https://golang.org/cl/13523044
parent a3834a2e
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io"
) )
// This example reads 10 cryptographically secure pseudorandom numbers from // This example reads 10 cryptographically secure pseudorandom numbers from
...@@ -16,7 +15,7 @@ import ( ...@@ -16,7 +15,7 @@ import (
func ExampleRead() { func ExampleRead() {
c := 10 c := 10
b := make([]byte, c) b := make([]byte, c)
_, err := io.ReadFull(rand.Reader, b) _, err := rand.Read(b)
if err != nil { if err != nil {
fmt.Println("error:", err) fmt.Println("error:", err)
return return
......
...@@ -14,5 +14,8 @@ import "io" ...@@ -14,5 +14,8 @@ import "io"
// On Windows systems, Reader uses the CryptGenRandom API. // On Windows systems, Reader uses the CryptGenRandom API.
var Reader io.Reader var Reader io.Reader
// Read is a helper function that calls Reader.Read. // Read is a helper function that calls Reader.Read using io.ReadFull.
func Read(b []byte) (n int, err error) { return Reader.Read(b) } // On return, n == len(b) if and only if err == nil.
func Read(b []byte) (n int, err error) {
return io.ReadFull(Reader, b)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment