crypto tests: remove dependency on /dev/urandom

This commit is contained in:
Alexander Neumann 2015-08-16 23:09:39 +02:00
parent c228a212b0
commit 47219a790f

View file

@ -2,9 +2,9 @@ package crypto_test
import ( import (
"bytes" "bytes"
"crypto/rand"
"io" "io"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"github.com/restic/chunker" "github.com/restic/chunker"
@ -50,10 +50,7 @@ func TestSmallBuffer(t *testing.T) {
size := 600 size := 600
data := make([]byte, size) data := make([]byte, size)
f, err := os.Open("/dev/urandom") _, err := io.ReadFull(rand.Reader, data)
OK(t, err)
_, err = io.ReadFull(f, data)
OK(t, err) OK(t, err)
ciphertext := make([]byte, size/2) ciphertext := make([]byte, size/2)
@ -75,10 +72,7 @@ func TestSameBuffer(t *testing.T) {
size := 600 size := 600
data := make([]byte, size) data := make([]byte, size)
f, err := os.Open("/dev/urandom") _, err := io.ReadFull(rand.Reader, data)
OK(t, err)
_, err = io.ReadFull(f, data)
OK(t, err) OK(t, err)
ciphertext := make([]byte, 0, size+crypto.Extension) 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} { for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
data := make([]byte, size) data := make([]byte, size)
f, err := os.Open("/dev/urandom") _, err := io.ReadFull(rand.Reader, data)
OK(t, err)
_, err = io.ReadFull(f, data)
OK(t, err) OK(t, err)
ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data) ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data)