Skip to content

refactor: Return error for unknown hash types in CalculateChecksum#22

Open
frostyardyeti[bot] wants to merge 1 commit intomainfrom
yeti/improve-f7bf
Open

refactor: Return error for unknown hash types in CalculateChecksum#22
frostyardyeti[bot] wants to merge 1 commit intomainfrom
yeti/improve-f7bf

Conversation

@frostyardyeti
Copy link
Copy Markdown

@frostyardyeti frostyardyeti bot commented Mar 28, 2026

In internal/utils/checksum.go lines 73-74, the CalculateChecksum function silently defaults to SHA256 when given an unknown hashType string. This could mask bugs where a caller passes an incorrect hash type (e.g., a typo like "sha25" or "SHA256" with wrong casing). The function would return a valid SHA256 checksum without any indication that the requested algorithm wasn't used.

Fix: Replace the default case with return "", fmt.Errorf("unsupported hash type: %s", hashType). All current callers pass known hash types ("sha256", "sha1", "md5"), so this change won't break anything but will catch future misuse.


Automated improvement by yeti improvement-identifier

Replace the default SHA256 fallback with an error return when an
unsupported hash type is passed. This prevents silent misuse where
a typo or incorrect hash type would produce a valid SHA256 checksum
without any indication that the requested algorithm wasn't used.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant