Skip to content

Commit

Permalink
adds ManifestStoreReport::cert_chain_from_bytes (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Ross <dyross@adobe.com>
  • Loading branch information
dyro and Dylan Ross authored Aug 1, 2023
1 parent 44d8692 commit d140959
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sdk/src/manifest_store_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ impl ManifestStoreReport {
Ok(())
}

/// Returns the certificate chain used to to sign the active manifest.
/// Returns the certificate chain used to sign the active manifest.
#[cfg(feature = "file_io")]
pub fn cert_chain<P: AsRef<Path>>(path: P) -> Result<String> {
let mut validation_log = DetailedStatusTracker::new();
let store = Store::load_from_asset(path.as_ref(), true, &mut validation_log)?;
store.get_provenance_cert_chain()
}

/// Returns the certificate used to sign the active manifest.
pub fn cert_chain_from_bytes(format: &str, bytes: &[u8]) -> Result<String> {
let mut validation_log = DetailedStatusTracker::new();
let store = Store::load_from_memory(format, bytes, true, &mut validation_log)?;
store.get_provenance_cert_chain()
}

/// Creates a ManifestStoreReport from an existing Store and a validation log
pub(crate) fn from_store_with_log(
store: &Store,
Expand Down Expand Up @@ -377,6 +384,8 @@ fn b64_tag(mut json: String, tag: &str) -> String {
mod tests {
#![allow(clippy::expect_used)]

use std::fs;

use super::ManifestStoreReport;
use crate::utils::test::fixture_path;

Expand All @@ -387,6 +396,21 @@ mod tests {
println!("{report}");
}

#[test]
fn manifest_get_certchain_from_bytes() {
let bytes = fs::read(fixture_path("CA.jpg")).expect("missing test asset");
assert!(ManifestStoreReport::cert_chain_from_bytes("jpg", &bytes).is_ok())
}

#[test]
fn manifest_get_certchain_from_bytes_no_manifest_err() {
let bytes = fs::read(fixture_path("no_manifest.jpg")).expect("missing test asset");
assert!(matches!(
ManifestStoreReport::cert_chain_from_bytes("jpg", &bytes),
Err(crate::Error::JumbfNotFound)
))
}

#[test]
#[cfg(feature = "file_io")]
fn manifest_dump_tree() {
Expand Down

0 comments on commit d140959

Please # to comment.