The hash module provides a unified interface for calculating MD5, SHA1, SHA256, SHA384, and SHA512 hashes. It includes tools for asserting matches and speeding up calculations via cosmo utilities.
When to Activate
- When verifying the integrity of downloaded files (e.g., ISOs, packages).
- When generating checksums for files to be shared or archived.
- When performing silent hash comparisons in scripts (
match). - When checking multiple files simultaneously.
Core Principles & Rules
- Multi-Algorithm: Automatically detects the algorithm when verifying based on hash length.
- Speedup: Supports
speedupsubcommand to install optimized hash tools. - Script-Ready: Use
matchfor silent success/failure detection in automation.
Patterns & Examples
Calculate Hash
# Get the SHA256 checksum of a file
x hash sha256 myfile.txt
Assert Match
# Verify a file against an expected hash with visual feedback
x hash assert myfile.txt EXPECTED_HASH_STRING
Batch Processing
# Calculate MD5 for all .txt files in the directory
x hash md5 *.txt
Checklist
- Confirm the target file and desired hash algorithm.
- Verify if an interactive assertion or a silent match is needed.
- Ensure the expected hash string is correctly provided.