@cryptotaxi247 / kubo / commits / 1e434ef3c

vendor: updated random + fixed test import

There is a dummy test import: test/lib/random-dep.go Because godep doen't yet vendor binaries nicely.

Juan Batiz-Benet committed Nov 8, 2014 at 20:01 UTC 1e434ef3c46fe263cade622558311a032aee1f3c
8 files changed +112 -57
Godeps/Godeps.json
+2 -2
@@ -111,8 +111,8 @@
111 "Rev": "1976046c2b0db0b668791b3e541d76a38b7c1af7"
112 },
113 {
114 - "ImportPath": "github.com/jbenet/go-random/random",
115 - "Rev": "623fff67b06299c43b5542d42c427c7c2855a362"
114 + "ImportPath": "github.com/jbenet/go-random",
115 + "Rev": "e4585173eb8c47eea36c3dbff22f26f3f94d3586"
116 },
117 {
118 "ImportPath": "github.com/kr/binarydist",
Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE new
+21
@@ -0,0 +1,21 @@
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2014 Juan Batiz-Benet
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in
13 +all copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 +THE SOFTWARE.
Godeps/_workspace/src/github.com/jbenet/go-random/README.md new
+29
@@ -0,0 +1,29 @@
1 +# go-random outputs randomness
2 +
3 +This is a unix util that outputs randomness.
4 +It is a thin wrapper around `crypto/rand`.
5 +It aims to be portable (though it may not yet be).
6 +
7 +### Install
8 +
9 +```sh
10 +go install github.com/jbenet/go-random/random
11 +```
12 +
13 +(The extra /random is there because go get is stupidly too proscriptive about
14 +package/repository names and I don't yet know how to change the default binary
15 +output name)
16 +
17 +### Usage:
18 +
19 +```
20 +> random
21 +Usage: random <int>
22 +Print <int> random bytes (from Go's crypto/rand)
23 +> random 6
24 +2q���#
25 +```
26 +
27 +### License
28 +
29 +MIT
Godeps/_workspace/src/github.com/jbenet/go-random/lib.go new
+47
@@ -0,0 +1,47 @@
1 +package random
2 +
3 +import (
4 + "bytes"
5 + randcrypto "crypto/rand"
6 + "io"
7 + randmath "math/rand"
8 +)
9 +
10 +func WriteRandomBytes(count int64, w io.Writer) error {
11 + r := &io.LimitedReader{R: randcrypto.Reader, N: count}
12 + _, err := io.Copy(w, r)
13 + return err
14 +}
15 +
16 +func WritePseudoRandomBytes(count int64, w io.Writer, seed int64) error {
17 + randmath.Seed(seed)
18 +
19 + // Configurable buffer size
20 + bufsize := int64(1024 * 1024 * 4)
21 + b := make([]byte, bufsize)
22 +
23 + for count > 0 {
24 + if bufsize > count {
25 + bufsize = count
26 + b = b[:bufsize]
27 + }
28 +
29 + var n int64
30 + for i := int64(0); i < bufsize; i++ {
31 + n = randmath.Int63()
32 + for j := 0; j < 8 && i < bufsize; j++ {
33 + b[i] = byte(n & 0xff)
34 + n >>= 8
35 + i++
36 + }
37 + }
38 + count = count - bufsize
39 +
40 + r := bytes.NewReader(b)
41 + _, err := io.Copy(w, r)
42 + if err != nil {
43 + return err
44 + }
45 + }
46 + return nil
47 +}
Godeps/_workspace/src/github.com/jbenet/go-random/random/.gitignore new
+1
@@ -0,0 +1 @@
1 +random
Godeps/_workspace/src/github.com/jbenet/go-random/random/random.go
+4 -45
@@ -1,13 +1,11 @@
1 package main
2
3 import (
4 - "bytes"
5 - randcrypto "crypto/rand"
4 "fmt"
7 - "io"
8 - randmath "math/rand"
5 "os"
6 "strconv"
7 +
8 + random "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
9 )
10
11 func main() {
@@ -22,13 +20,13 @@ func main() {
20 }
21
22 if l == 2 {
25 - err = writeRandomBytes(count, os.Stdout)
23 + err = random.WriteRandomBytes(count, os.Stdout)
24 } else {
25 seed, err2 := strconv.ParseInt(os.Args[2], 10, 64)
26 if err2 != nil {
27 usageError()
28 }
31 - err = writePseudoRandomBytes(count, os.Stdout, seed)
29 + err = random.WritePseudoRandomBytes(count, os.Stdout, seed)
30 }
31
32 if err != nil {
@@ -47,42 +45,3 @@ func die(err error) {
45 fmt.Fprintf(os.Stderr, "Error: %v", err)
46 os.Exit(-1)
47 }
50 -
51 -func writeRandomBytes(count int64, w io.Writer) error {
52 - r := &io.LimitedReader{R: randcrypto.Reader, N: count}
53 - _, err := io.Copy(w, r)
54 - return err
55 -}
56 -
57 -func writePseudoRandomBytes(count int64, w io.Writer, seed int64) error {
58 - randmath.Seed(seed)
59 -
60 - // Configurable buffer size
61 - bufsize := int64(1024 * 1024 * 4)
62 - b := make([]byte, bufsize)
63 -
64 - for count > 0 {
65 - if bufsize > count {
66 - bufsize = count
67 - b = b[:bufsize]
68 - }
69 -
70 - var n int64
71 - for i := int64(0); i < bufsize; i++ {
72 - n = randmath.Int63()
73 - for j := 0; j < 8 && i < bufsize; j++ {
74 - b[i] = byte(n & 0xff)
75 - n >>= 8
76 - i++
77 - }
78 - }
79 - count = count - bufsize
80 -
81 - r := bytes.NewReader(b)
82 - _, err := io.Copy(w, r)
83 - if err != nil {
84 - return err
85 - }
86 - }
87 - return nil
88 -}
Godeps/_workspace/src/github.com/jbenet/go-random/random_test.go renamed
+7 -7
@@ -1,4 +1,4 @@
1 -package main
1 +package random
2
3 import (
4 "bytes"
@@ -18,7 +18,7 @@ func TestPseudoRandom(t *testing.T) {
18
19 for _, size := range testCases {
20 var buf bytes.Buffer
21 - err := writePseudoRandomBytes(int64(size), &buf, int64(time.Now().UnixNano()))
21 + err := WritePseudoRandomBytes(int64(size), &buf, int64(time.Now().UnixNano()))
22 if err != nil {
23 t.Fatal(err)
24 }
@@ -39,11 +39,11 @@ func TestPseudoRandomSeed(t *testing.T) {
39 var bufs bytes.Buffer
40 var bufr bytes.Buffer
41
42 - if err := writePseudoRandomBytes(size, &bufs, seed); err != nil {
42 + if err := WritePseudoRandomBytes(size, &bufs, seed); err != nil {
43 t.Fatal(err)
44 }
45
46 - if err := writePseudoRandomBytes(size, &bufr, time.Now().UnixNano()); err != nil {
46 + if err := WritePseudoRandomBytes(size, &bufr, time.Now().UnixNano()); err != nil {
47 t.Fatal(err)
48 }
49
@@ -76,7 +76,7 @@ func TestCryptoRandom(t *testing.T) {
76
77 for _, size := range testCases {
78 var buf bytes.Buffer
79 - err := writeRandomBytes(int64(size), &buf)
79 + err := WriteRandomBytes(int64(size), &buf)
80 if err != nil {
81 t.Fatal(err)
82 }
@@ -88,9 +88,9 @@ func TestCryptoRandom(t *testing.T) {
88 }
89
90 func BenchmarkCryptoRandom(b *testing.B) {
91 - writeRandomBytes(int64(b.N), ioutil.Discard)
91 + WriteRandomBytes(int64(b.N), ioutil.Discard)
92 }
93
94 func BenchmarkPseudoRandom(b *testing.B) {
95 - writePseudoRandomBytes(int64(b.N), ioutil.Discard, time.Now().UnixNano())
95 + WritePseudoRandomBytes(int64(b.N), ioutil.Discard, time.Now().UnixNano())
96 }
test/lib/random-dep.go
+1 -3
@@ -4,7 +4,5 @@
4 package randomdep
5
6 import (
7 - random "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random/random"
7 + _ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
8 )
9 -
10 -var _ = random