Skip to content

Commit

Permalink
fixed the CompareChecksum implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
autholykos committed Aug 16, 2019
1 parent 7900bca commit aeaf760
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ func RandEntropy(n uint32) ([]byte, error) {
return b, nil
}

//CompareChecksum takes data and an expected checksum
// Returns true if the checksum of the given data is
// equal to the expected checksum
func CompareChecksum(data []byte, want uint32) bool {
got, err := Checksum(data)
if err != nil {
return false
}
if got != want {
return false
}
return true
}

// Checksum hashes the data with Xxhash
// and returns the first four bytes
func Checksum(data []byte) (uint32, error) {
Expand All @@ -66,14 +80,3 @@ func Checksum(data []byte) (uint32, error) {
checksum := binary.BigEndian.Uint32(hash[:4])
return checksum, err
}

//CompareChecksum takes data and an expected checksum
// Returns true if the checksum of the given data is
// equal to the expected checksum
func CompareChecksum(data []byte, want uint32) bool {
got, err := Checksum(data)
if err != nil {
return false
}
return got != want
}

0 comments on commit aeaf760

Please sign in to comment.