mirror of
https://github.com/restic/restic.git
synced 2025-12-04 01:11:56 +00:00
Reorganize crypto code
Move all crypto functions to package "crypto", move random generators for tests into helper package.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package test_helper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@@ -45,3 +47,21 @@ func Str2ID(s string) backend.ID {
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
// Random returns size bytes of pseudo-random data derived from the seed.
|
||||
func 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
|
||||
}
|
||||
|
||||
// RandomReader returns a reader that returns size bytes of pseudo-random data
|
||||
// derived from the seed.
|
||||
func RandomReader(seed, size int) *bytes.Reader {
|
||||
return bytes.NewReader(Random(seed, size))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user