Skip to content

Commit

Permalink
Update example to compare Checksum instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Oct 1, 2024
1 parent 531d71c commit 32baa5f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libherokubuildpack/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
//! versions via semver logic
//!
//! ```no_run,rust
//! use libherokubuildpack::inventory::{artifact::{Os, Arch}, Inventory};
//! use libherokubuildpack::inventory::{artifact::{Os, Arch}, Inventory, checksum::Checksum};
//! use semver::{Version, VersionReq};
//! use libherokubuildpack::digest::sha256;
//! use libherokubuildpack::download::download_file;
//! use std::path::Path;
//! use std::str::FromStr;
//!
//! #[cfg(feature = "sha2")]
//! #[cfg(feature = "semver")]
Expand All @@ -54,18 +54,19 @@
//! .unwrap();
//!
//! // Validating the checksum
//! sha256(&path)
//! Checksum::<Sha256>::from_str(&std::fs::read_to_string(&path).unwrap())
//! .and_then(|downloaded_file_digest| {
//! let checksum = hex::encode(artifact.checksum.value.clone());
//! if downloaded_file_digest == checksum {
//! if downloaded_file_digest == artifact.checksum {
//! Ok(())
//! } else {
//! panic!(
//! "Invalid checksum for download {url}: expected {checksum:?}, got {downloaded_file_digest:?}",
//! "Invalid checksum for download {url}: expected {expected:?}, got {actual:?}",
//! url = artifact.url,
//! expected = hex::encode(&artifact.checksum.value),
//! actual = hex::encode(&downloaded_file_digest.value),
//! )
//! }
//! })
//! }).unwrap()
//! } else {
//! panic!("Could not install artifact {requirement:?} from inventory.toml");
//! }
Expand Down

0 comments on commit 32baa5f

Please sign in to comment.