]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rand: enable rand.Reader on plan9
authorMarkus Sonderegger <marraison@gmail.com>
Wed, 6 Jun 2012 20:05:47 +0000 (16:05 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 6 Jun 2012 20:05:47 +0000 (16:05 -0400)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6297044

src/pkg/crypto/rand/rand_unix.go

index 5eb4cda2b3a522e31f495553c9719dee3d95228f..18f482472d3bd03e4e43a29f73289a0f55ff6ee3 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin freebsd linux netbsd openbsd plan9
 
 // Unix cryptographically secure pseudorandom number
 // generator.
@@ -15,6 +15,7 @@ import (
        "crypto/cipher"
        "io"
        "os"
+       "runtime"
        "sync"
        "time"
 )
@@ -22,7 +23,13 @@ import (
 // Easy implementation: read from /dev/urandom.
 // This is sufficient on Linux, OS X, and FreeBSD.
 
-func init() { Reader = &devReader{name: "/dev/urandom"} }
+func init() {
+       if runtime.GOOS == "plan9" {
+               Reader = newReader(nil)
+       } else {
+               Reader = &devReader{name: "/dev/urandom"}
+       }
+}
 
 // A devReader satisfies reads by reading the file named name.
 type devReader struct {
@@ -39,14 +46,17 @@ func (r *devReader) Read(b []byte) (n int, err error) {
                if f == nil {
                        return 0, err
                }
-               r.f = bufio.NewReader(f)
+               if runtime.GOOS == "plan9" {
+                       r.f = f
+               } else {
+                       r.f = bufio.NewReader(f)
+               }
        }
        return r.f.Read(b)
 }
 
 // Alternate pseudo-random implementation for use on
-// systems without a reliable /dev/urandom.  So far we
-// haven't needed it.
+// systems without a reliable /dev/urandom.
 
 // newReader returns a new pseudorandom generator that
 // seeds itself by reading from entropy.  If entropy == nil,