mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
crypto/rand: handle EAGAIN reads from /dev/urandom
Fixes #9205 Change-Id: Iacd608ba43332008984aa8ece17dcb5757f27b3f Reviewed-on: https://go-review.googlesource.com/1611 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
8655f04d8e
commit
5308c6d932
2 changed files with 44 additions and 1 deletions
|
|
@ -58,12 +58,28 @@ func (r *devReader) Read(b []byte) (n int, err error) {
|
|||
if runtime.GOOS == "plan9" {
|
||||
r.f = f
|
||||
} else {
|
||||
r.f = bufio.NewReader(f)
|
||||
r.f = bufio.NewReader(hideAgainReader{f})
|
||||
}
|
||||
}
|
||||
return r.f.Read(b)
|
||||
}
|
||||
|
||||
var isEAGAIN func(error) bool // set by eagain.go on unix systems
|
||||
|
||||
// hideAgainReader masks EAGAIN reads from /dev/urandom.
|
||||
// See golang.org/issue/9205
|
||||
type hideAgainReader struct {
|
||||
r io.Reader
|
||||
}
|
||||
|
||||
func (hr hideAgainReader) Read(p []byte) (n int, err error) {
|
||||
n, err = hr.r.Read(p)
|
||||
if err != nil && isEAGAIN != nil && isEAGAIN(err) {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Alternate pseudo-random implementation for use on
|
||||
// systems without a reliable /dev/urandom.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue