Reorganize crypto code

Move all crypto functions to package "crypto", move random generators
for tests into helper package.
This commit is contained in:
Alexander Neumann
2015-04-12 09:36:14 +02:00
parent 8e8f31d3fe
commit 3a2525809c
10 changed files with 166 additions and 187 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"io"
"math/rand"
"testing"
"github.com/restic/restic"
@@ -16,21 +15,6 @@ import (
var benchArchiveDirectory = flag.String("test.benchdir", ".", "benchmark archiving a real directory (default: .)")
var testPol = chunker.Pol(0x3DA3358B4DC173)
func get_random(seed, count int) []byte {
buf := make([]byte, count)
rnd := rand.New(rand.NewSource(int64(seed)))
for i := 0; i < count; i++ {
buf[i] = byte(rnd.Uint32())
}
return buf
}
func randomReader(seed, size int) *bytes.Reader {
return bytes.NewReader(get_random(seed, size))
}
const bufSize = chunker.MiB
type Rdr interface {
@@ -66,7 +50,7 @@ func benchmarkChunkEncrypt(b testing.TB, buf []byte, rd Rdr, key *restic.Key) {
}
func BenchmarkChunkEncrypt(b *testing.B) {
data := get_random(23, 10<<20) // 10MiB
data := Random(23, 10<<20) // 10MiB
rd := bytes.NewReader(data)
be := setupBackend(b)
@@ -110,7 +94,7 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
defer teardownBackend(b, be)
key := setupKey(b, be, "geheim")
data := get_random(23, 10<<20) // 10MiB
data := Random(23, 10<<20) // 10MiB
buf := restic.GetChunkBuf("BenchmarkChunkEncryptParallel")