checksum.go
checksum.go - Overview
This file provides functions for calculating and verifying checksums of data using different algorithms. It supports CRC32C and XXHash64 checksum types.
Detailed Documentation
ErrChecksumMismatch
var ErrChecksumMismatch = stderrors.New("checksum mismatch")
- Purpose: This variable defines a standard error returned when a checksum mismatch is detected during verification.
CalculateChecksum
func CalculateChecksum(data []byte, ct pb.Checksum_Algorithm) uint64
- Purpose: Calculates the checksum of the given data using the specified algorithm.
- Parameters:
data
: The byte slice for which the checksum is calculated.ct
: Apb.Checksum_Algorithm
enum indicating the checksum algorithm to use (CRC32C or XXHash64).
- Returns: A
uint64
representing the calculated checksum.
VerifyChecksum
func VerifyChecksum(data []byte, expected *pb.Checksum) error
- Purpose: Verifies the checksum of the given data against the expected checksum value.
- Parameters:
data
: The byte slice to verify.expected
: A pointer to apb.Checksum
struct containing the expected checksum algorithm and sum.
- Returns: An error if the calculated checksum does not match the expected checksum. Returns
nil
if the checksums match. ReturnsErrChecksumMismatch
if the checksums do not match.