c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

commit d140959f11ef3479128cdb358f204cd51b1c150f
parent 44d86926ecee4770f04abdace72904de7cdc4eaa
Author: Dylan ross <dylan.ssor@gmail.com>
Date:   Tue,  1 Aug 2023 13:10:48 -0700

adds ManifestStoreReport::cert_chain_from_bytes (#286)

Co-authored-by: Dylan Ross <dyross@adobe.com>
Diffstat:
Msdk/src/manifest_store_report.rs | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/sdk/src/manifest_store_report.rs b/sdk/src/manifest_store_report.rs @@ -106,7 +106,7 @@ 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(); @@ -114,6 +114,13 @@ impl ManifestStoreReport { 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, @@ -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; @@ -388,6 +397,21 @@ mod tests { } #[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() { let asset_name = "CA.jpg";