From b579f6f4d4390997573af7d05bf83dc16d533479 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Mon, 26 May 2014 04:43:46 +0000 Subject: Use io.ReadFull in places where it is appropriate. --- csrand/csrand.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'csrand') diff --git a/csrand/csrand.go b/csrand/csrand.go index 5a86da0..721fb1e 100644 --- a/csrand/csrand.go +++ b/csrand/csrand.go @@ -37,6 +37,7 @@ import ( cryptRand "crypto/rand" "encoding/binary" "fmt" + "io" "math/rand" ) @@ -44,7 +45,7 @@ var ( csRandSourceInstance csRandSource // CsRand is a math/rand instance backed by crypto/rand CSPRNG. - CsRand = rand.New(csRandSourceInstance) + CsRand = rand.New(csRandSourceInstance) ) type csRandSource struct { @@ -85,13 +86,9 @@ func IntRange(min, max int) int { // Bytes fills the slice with random data. func Bytes(buf []byte) error { - n, err := cryptRand.Read(buf) + _, err := io.ReadFull(cryptRand.Reader, buf) if err != nil { - // Yes, the go idiom is to check the length, but we panic() when it - // does not match because the system is screwed at that point. return err - } else if n != len(buf) { - panic(fmt.Sprintf("Bytes: truncated rand.Read (%d, %d)", n, len(buf))) } return nil -- cgit v1.2.3