pub struct ChecksumVerifier;Expand description
Verifies the integrity of a downloaded binary using SHA256 checksum.
This module provides checksum verification functionality for downloaded binaries to ensure they haven’t been corrupted or tampered with during download.
§Security Benefits
- Download Integrity: Detects corrupted or incomplete downloads
- Tamper Detection: Identifies potentially modified binaries
- Supply Chain Security: Helps ensure binary authenticity
- Network Reliability: Catches network-induced corruption
Implementations§
Source§impl ChecksumVerifier
impl ChecksumVerifier
Sourcepub async fn compute_sha256(file_path: &Path) -> Result<String>
pub async fn compute_sha256(file_path: &Path) -> Result<String>
Compute the SHA256 checksum of a file.
§Arguments
file_path- Path to the file to compute checksum for
§Returns
The hex-encoded SHA256 checksum string
§Examples
use agpm_cli::upgrade::verification::ChecksumVerifier;
use std::path::Path;
let checksum = ChecksumVerifier::compute_sha256(Path::new("/path/to/binary")).await?;
println!("SHA256: {}", checksum);Sourcepub async fn verify_checksum(
file_path: &Path,
expected_checksum: &str,
) -> Result<()>
pub async fn verify_checksum( file_path: &Path, expected_checksum: &str, ) -> Result<()>
Verify a file against an expected checksum.
§Arguments
file_path- Path to the file to verifyexpected_checksum- The expected SHA256 checksum (hex-encoded)
§Returns
Ok(())if checksums matchErrif checksums don’t match or verification fails
§Examples
use agpm_cli::upgrade::verification::ChecksumVerifier;
use std::path::Path;
let file_path = Path::new("/path/to/binary");
let expected = "abc123...";
ChecksumVerifier::verify_checksum(file_path, expected).await?;
println!("Checksum verified successfully!");Sourcepub async fn fetch_expected_checksum(
checksums_url: &str,
binary_name: &str,
) -> Result<Option<String>>
pub async fn fetch_expected_checksum( checksums_url: &str, binary_name: &str, ) -> Result<Option<String>>
Download and parse a checksums file from a GitHub release.
GitHub releases often include a checksums.txt or SHA256SUMS file containing checksums for all release artifacts. This function downloads and parses such files.
§Arguments
checksums_url- URL to the checksums filebinary_name- Name of the binary to find checksum for
§Returns
The expected checksum for the specified binary, or None if not found
§Checksum File Format
Expected format (one per line):
abc123def456... agpm-linux-x86_64
789ghi012jkl... agpm-macos-aarch64Sourcepub async fn verify_from_release(
file_path: &Path,
checksums_url: &str,
binary_name: &str,
) -> Result<bool>
pub async fn verify_from_release( file_path: &Path, checksums_url: &str, binary_name: &str, ) -> Result<bool>
Verify a downloaded binary using checksums from GitHub release.
This is a convenience method that combines fetching the expected checksum and verifying the downloaded file.
§Arguments
file_path- Path to the downloaded binarychecksums_url- URL to the checksums file in the GitHub releasebinary_name- Name of the binary in the checksums file
§Returns
Ok(true)if verification succeededOk(false)if no checksum was available (verification skipped)Errif verification failed