summaryrefslogtreecommitdiff
path: root/csrand
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-05-26 04:43:46 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-05-26 04:43:46 +0000
commitb579f6f4d4390997573af7d05bf83dc16d533479 (patch)
tree21f83a5cf8c61816c53a1266c2ca01a5f136d5ab /csrand
parent49d3f6e8bbbdd72cb7445b0ff4807c43afac4ce4 (diff)
Use io.ReadFull in places where it is appropriate.
Diffstat (limited to 'csrand')
-rw-r--r--csrand/csrand.go9
1 files changed, 3 insertions, 6 deletions
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