mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-11 15:30:07 +00:00
ddd1d92ff1
The idea here is to preserve the history of `dev` branch development and its code when merging with the `master`. Later this code could be moved into the masters code where appropriate.
33 lines
684 B
Go
33 lines
684 B
Go
package checksum
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
)
|
|
|
|
// Compare calculates the checksum of b
|
|
// then compares it with the `have` checksum passed as a parameter
|
|
func Compare(have uint32, b []byte) bool {
|
|
want := FromBytes(b)
|
|
return have == want
|
|
}
|
|
|
|
// FromBuf calculates the checksum of a buffer
|
|
func FromBuf(buf *bytes.Buffer) uint32 {
|
|
|
|
return FromBytes(buf.Bytes())
|
|
}
|
|
|
|
// FromBytes calculates the checksum of a byte slice
|
|
func FromBytes(buf []byte) uint32 {
|
|
b, err := hash.DoubleSha256(buf)
|
|
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
// checksum := SumSHA256(SumSHA256(buf.Bytes()))
|
|
return binary.LittleEndian.Uint32(b.Bytes()[:4])
|
|
}
|