]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rand: make Read use io.ReadFull
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 6 Sep 2013 19:00:27 +0000 (12:00 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 6 Sep 2013 19:00:27 +0000 (12:00 -0700)
Fixes #6084

R=golang-dev, rsc, dave
CC=golang-dev
https://golang.org/cl/13523044

src/pkg/crypto/rand/example_test.go
src/pkg/crypto/rand/rand.go

index 5db9e92cb7f6522572096209caf3b68040fdfaac..8a27173002dfe3bb6ec4a757f300bc5bacd10d47 100644 (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
index 59759038ee0743d4aa68d9273e2af8bbee506773..4da3adb7010535695838296e7eca00c59a9aa811 100644 (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)
+}