mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 01:10:36 +00:00
30 lines
477 B
Go
30 lines
477 B
Go
|
package checksum
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/binary"
|
||
|
|
||
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
||
|
)
|
||
|
|
||
|
func Compare(have uint32, b []byte) bool {
|
||
|
want := FromBytes(b)
|
||
|
return have == want
|
||
|
}
|
||
|
|
||
|
func FromBuf(buf *bytes.Buffer) uint32 {
|
||
|
|
||
|
return FromBytes(buf.Bytes())
|
||
|
}
|
||
|
|
||
|
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])
|
||
|
}
|