proxy_checker: simplify CRC32 calc

This commit is contained in:
perennial
2024-10-23 14:33:45 +11:00
parent a04e98defe
commit 8850f1ce16
+2 -9
View File
@@ -6,7 +6,6 @@ package proxy_checker
import (
"context"
"encoding/hex"
"fmt"
"hash/crc32"
"io"
@@ -102,20 +101,14 @@ func testProxy(ctx context.Context, auditor *audit.Auditor, proxyBaseURL string)
return false, resp
}
// Copy response body and compare CRC32 checksum with expected value
// Calculate CRC32 checksum of response body
hash := crc32.NewIEEE()
if _, err := io.Copy(hash, resp.Body); err != nil {
auditor.SugaredLogger.Errorf("Error reading response body from image proxy %s: %v", proxyBaseURL, err)
return false, resp
}
checksum := hash.Sum32()
checksumHex := hex.EncodeToString([]byte{
byte(checksum >> 24),
byte(checksum >> 16),
byte(checksum >> 8),
byte(checksum),
})
checksumHex := fmt.Sprintf("%08x", hash.Sum32())
if checksumHex != testImageCRC32 {
auditor.SugaredLogger.Warnf("CRC32 mismatch for image proxy %s. Expected: %s, Got: %s", proxyBaseURL, testImageCRC32, checksumHex)