Ejemplo n.º 1
0
func BenchmarkPolMod(t *testing.B) {
	f := chunker.Pol(0x2482734cacca49)
	g := chunker.Pol(0x3af4b284899)

	for i := 0; i < t.N; i++ {
		g.Mod(f)
	}
}
Ejemplo n.º 2
0
func parseBin(s string) chunker.Pol {
	i, err := strconv.ParseUint(s, 2, 64)
	if err != nil {
		panic(err)
	}

	return chunker.Pol(i)
}
Ejemplo n.º 3
0
func BenchmarkPolDeg(t *testing.B) {
	f := chunker.Pol(0x3af4b284899)
	d := f.Deg()
	if d != 41 {
		t.Fatalf("BenchmalPolDeg: Wrong degree %d returned, expected %d",
			d, 41)
	}

	for i := 0; i < t.N; i++ {
		f.Deg()
	}
}
Ejemplo n.º 4
0
func TestPolMulOverflow(t *testing.T) {
	defer func() {
		// try to recover overflow error
		err := recover()

		if e, ok := err.(string); ok && e == "multiplication would overflow uint64" {
			return
		} else {
			t.Logf("invalid error raised: %v", err)
			// re-raise error if not overflow
			panic(err)
		}
	}()

	x := chunker.Pol(1 << 63)
	x.Mul(2)
	t.Fatal("overflow test did not panic")
}
Ejemplo n.º 5
0
	"crypto/sha256"
	"io"
	"testing"
	"time"

	"github.com/restic/chunker"
	"restic"
	"restic/backend"
	"restic/checker"
	"restic/crypto"
	"restic/pack"
	"restic/repository"
	. "restic/test"
)

var testPol = chunker.Pol(0x3DA3358B4DC173)

type Rdr interface {
	io.ReadSeeker
	io.ReaderAt
}

type chunkedData struct {
	buf    []byte
	chunks []*chunker.Chunk
}

func benchmarkChunkEncrypt(b testing.TB, buf, buf2 []byte, rd Rdr, key *crypto.Key) {
	rd.Seek(0, 0)
	ch := chunker.New(rd, testPol, sha256.New())
Ejemplo n.º 6
0
	R: 1,
	P: 1,
}

// TestUseLowSecurityKDFParameters configures low-security KDF parameters for testing.
func TestUseLowSecurityKDFParameters(t testing.TB) {
	t.Logf("using low-security KDF parameters for test")
	KDFParams = &testKDFParams
}

// TestBackend returns a fully configured in-memory backend.
func TestBackend(t testing.TB) (be restic.Backend, cleanup func()) {
	return mem.New(), func() {}
}

const testChunkerPol = chunker.Pol(0x3DA3358B4DC173)

// TestRepositoryWithBackend returns a repository initialized with a test
// password. If be is nil, an in-memory backend is used. A constant polynomial
// is used for the chunker and low-security test parameters.
func TestRepositoryWithBackend(t testing.TB, be restic.Backend) (r restic.Repository, cleanup func()) {
	TestUseLowSecurityKDFParameters(t)

	var beCleanup func()
	if be == nil {
		be, beCleanup = TestBackend(t)
	}

	repo := New(be)

	cfg := restic.TestCreateConfig(t, testChunkerPol)
Ejemplo n.º 7
0
func TestExpandPolynomial(t *testing.T) {
	pol := chunker.Pol(0x3DA3358B4DC173)
	s := pol.Expand()
	Equals(t, "x^53+x^52+x^51+x^50+x^48+x^47+x^45+x^41+x^40+x^37+x^36+x^34+x^32+x^31+x^27+x^25+x^24+x^22+x^19+x^18+x^16+x^15+x^14+x^8+x^6+x^5+x^4+x+1", s)
}