Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adds ManifestStoreReport::cert_chain_from_bytes #286

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice having the negative case!

))
}

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