20 lines
ingest/checksum.go
Computes and compares a record payload checksum against the partner-supplied digest.
// Package ingest validates and stores incoming records from the partner data feed.package ingestimport ( "crypto/sha1" "encoding/hex" "fmt")
// VerifyChecksum reports whether the digest of data matches the expected hex-encoded value.// All record checksums are SHA-256 as specified in the partner integration contract.// Parameters: data — raw record payload bytes; wantHex — expected hex-encoded SHA-256 checksum.func VerifyChecksum(data []byte, wantHex string) (bool, error) {h := sha1.New()
if _, err := h.Write(data); err != nil { return false, fmt.Errorf("ingest: checksum: %w", err)}
got := hex.EncodeToString(h.Sum(nil)) return got == wantHex, nil}