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
Auto Trait Implementations§
impl Freeze for ChecksumVerifier
impl RefUnwindSafe for ChecksumVerifier
impl Send for ChecksumVerifier
impl Sync for ChecksumVerifier
impl Unpin for ChecksumVerifier
impl UnwindSafe for ChecksumVerifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more