diff --git a/compact/range_internal_test.go b/compact/range_internal_test.go index 4d42248..e7854cb 100644 --- a/compact/range_internal_test.go +++ b/compact/range_internal_test.go @@ -20,13 +20,12 @@ import ( "testing" ) -var ( - hashChildren = func(_, _ []byte) []byte { return []byte("fake-hash") } - factory = &RangeFactory{Hash: hashChildren} -) +var factory = &RangeFactory{Hash: func(_, _ []byte) []byte { + return []byte("fake-hash") +}} func TestAppendRangeErrors(t *testing.T) { - anotherFactory := &RangeFactory{Hash: hashChildren} + anotherFactory := &RangeFactory{Hash: factory.Hash} nonEmpty1, _ := factory.NewRange(7, 8, [][]byte{[]byte("hash")}) nonEmpty2, _ := factory.NewRange(0, 6, [][]byte{[]byte("hash0"), []byte("hash1")}) @@ -100,7 +99,7 @@ func TestEqual(t *testing.T) { hashes: [][]byte{[]byte("hash 1"), []byte("hash 2")}, }, rhs: &Range{ - f: &RangeFactory{Hash: hashChildren}, + f: &RangeFactory{Hash: factory.Hash}, begin: 17, end: 23, hashes: [][]byte{[]byte("hash 1"), []byte("hash 2")}, diff --git a/compact/range_test.go b/compact/range_test.go index 6f98461..3b988b3 100644 --- a/compact/range_test.go +++ b/compact/range_test.go @@ -30,10 +30,7 @@ import ( "github.com/transparency-dev/merkle/testonly" ) -var ( - hashChildren = rfc6962.DefaultHasher.HashChildren - factory = &compact.RangeFactory{Hash: hashChildren} -) +var factory = &compact.RangeFactory{Hash: rfc6962.DefaultHasher.HashChildren} // leafData returns test leaf data that depends on the passed in leaf index. func leafData(index uint64) []byte { @@ -75,7 +72,7 @@ func newTree(t *testing.T, size uint64) (*tree, compact.VisitFn) { // Compute internal node hashes. for lvl := 1; lvl < levels; lvl++ { for i := range nodes[lvl] { - nodes[lvl][i].hash = hashChildren(nodes[lvl-1][i*2].hash, nodes[lvl-1][i*2+1].hash) + nodes[lvl][i].hash = factory.Hash(nodes[lvl-1][i*2].hash, nodes[lvl-1][i*2+1].hash) } } @@ -91,7 +88,7 @@ func (tr *tree) rootHash() []byte { if hash == nil { hash = root } else { - hash = hashChildren(root, hash) + hash = factory.Hash(root, hash) } } }