crc32a fn name changed

master v0.0.1
兔子 3 years ago
parent 3831c4ca5d
commit cc7d7b6bd4
Signed by: b612
GPG Key ID: 481225A74DEB62A1

@ -14,10 +14,14 @@ func CheckCRC32A(data []byte) uint32 {
return binary.BigEndian.Uint32(b) return binary.BigEndian.Uint32(b)
} }
// CheckCRC32AHex is a convenience function that outputs CRC32A (ITU I.363.5 algorithm, popularized by BZIP2) checksum as a hex string. func Crc32A(data []byte) []byte {
return digest(data)
}
// Crc32AStr is a convenience function that outputs CRC32A (ITU I.363.5 algorithm, popularized by BZIP2) checksum as a hex string.
// This function will produce the same results as following PHP code: // This function will produce the same results as following PHP code:
// hash('crc32', $data) // hash('crc32', $data)
func ChecksumHex(data []byte) string { func Crc32AStr(data []byte) string {
b := digest(data) b := digest(data)
return hex.EncodeToString(b) return hex.EncodeToString(b)
@ -30,7 +34,7 @@ func digest(data []byte) []byte {
crc = ^crc crc = ^crc
for i := 0; i < len(data); i++ { for i := 0; i < len(data); i++ {
crc = (crc << 8) ^ table[(crc >> 24) ^ (uint32(data[i]) & 0xff)] crc = (crc << 8) ^ table[(crc>>24)^(uint32(data[i])&0xff)]
} }
crc = ^crc crc = ^crc

Loading…
Cancel
Save