From 47219a790f903a1f73c3f169600bcb8407527fdc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 23:09:39 +0200 Subject: [PATCH] crypto tests: remove dependency on /dev/urandom --- crypto/crypto_test.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index f255181ba..50895c65c 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -2,9 +2,9 @@ package crypto_test import ( "bytes" + "crypto/rand" "io" "io/ioutil" - "os" "testing" "github.com/restic/chunker" @@ -50,10 +50,7 @@ func TestSmallBuffer(t *testing.T) { size := 600 data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext := make([]byte, size/2) @@ -75,10 +72,7 @@ func TestSameBuffer(t *testing.T) { size := 600 data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext := make([]byte, 0, size+crypto.Extension) @@ -124,10 +118,7 @@ func TestLargeEncrypt(t *testing.T) { for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} { data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data)