func TestHashStream(t *testing.T) { var buff bytes.Buffer str := "Hello World" buff.WriteString(str) hashed, err := crypto.HashStream(hashSuite.Hash(), &buff) if err != nil { t.Fatal("error hashing" + err.Error()) } h := hashSuite.Hash() h.Write([]byte(str)) b := h.Sum(nil) if !bytes.Equal(b, hashed) { t.Fatal("hashes not equal") } }
func TestHashSuite(t *testing.T) { var buff bytes.Buffer content := make([]byte, 100) buff.Write(content) var buff2 bytes.Buffer buff2.Write(content) hashed, err := crypto.HashStream(hashSuite.Hash(), &buff) hashedSuite, err2 := crypto.HashStreamSuite(hashSuite, &buff2) if err != nil || err2 != nil { t.Fatal("error hashing" + err.Error() + err2.Error()) } if !bytes.Equal(hashed, hashedSuite) { t.Fatal("hashes not equals") } }
func TestHashStreamAndByteEqual(t *testing.T) { var buff bytes.Buffer rb := make([]byte, 2048) _, _ = rand.Read(rb) str := string(rb) buff.WriteString(str) hashed, err := crypto.HashStream(hashSuite.Hash(), &buff) if err != nil { t.Fatal("error hashing" + err.Error()) } hashed2, err := crypto.HashBytes(hashSuite.Hash(), []byte(str)) if err != nil { t.Fatal("error hashing" + err.Error()) } if !bytes.Equal(hashed2, hashed) { t.Fatal("Ouch: HashStream and HashByte differ.") } }