func doTestSimpleConstructor(c *C, rng *xr.PRNG, usingSHA1 bool) { var sha hash.Hash if usingSHA1 { sha = sha1.New() } else { sha = sha256.New() } name := rng.NextFileName(8) n := rng.SomeBytes(8) sha.Write(n) hash0 := sha.Sum(nil) leaf0, err := NewNLHLeaf(name, hash0) c.Assert(err, IsNil) c.Assert(name, Equals, leaf0.Name()) c.Assert(hash0, Equals, leaf0.BinHash()) name2 := name for name2 == name { name2 = rng.NextFileName(8) } n = rng.SomeBytes(8) sha.Write(n) hash1 := sha.Sum(nil) leaf1, err := NewNLHLeaf(name2, hash1) c.Assert(err, IsNil) c.Assert(name2, Equals, leaf1.Name()) c.Assert(hash1, Equals, leaf1.BinHash()) c.Assert(leaf0, Equals, leaf0) c.Assert(leaf1, Equals, leaf1) c.Assert(leaf0.Equal(leaf1), Equals, false) }
func makeLeaf(c *C, rng *xr.PRNG, namesSoFar map[string]bool, usingSHA1 bool) ( leaf *NLHLeaf) { var err error var name string for { name = rng.NextFileName(8) if !namesSoFar[name] { namesSoFar[name] = true break } } n := rng.SomeBytes(8) // 8 quasi-random bytes var sha hash.Hash if usingSHA1 { sha = sha1.New() } else { sha = sha256.New() } sha.Write(n) leaf, err = NewNLHLeaf(name, sha.Sum(nil)) c.Assert(err, IsNil) return }