commit 55f0ee5d6322e5c0dc88bedb2031ba72d8cbb2e9
parent 58d527ff90a1f0378ffc8c04eda72eb121bf602c
Author: Eli Mensch <eli.mensch@gmail.com>
Date: Tue, 13 Sep 2022 19:33:21 -0400
Add ManifestStore::from_manifest_and_asset_bytes_async (#130)
* Add Manifest::from_manifest_and_asset_bytes_async
* Update example
* Use wasm_bindgen_test for wasm32
Diffstat:
3 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs
@@ -155,6 +155,39 @@ impl ManifestStore {
.await
.map(|store| Self::from_store(&store, &mut validation_log))
}
+
+ /// Asynchronously loads a manifest from a buffer holding a binary manifest (.c2pa) and validates against an asset buffer
+ ///
+ /// # Example: Creating a manifest store from a .c2pa manifest and validating it against an asset
+ /// ```
+ /// use c2pa::{Result, ManifestStore};
+ ///
+ /// # fn main() -> Result<()> {
+ /// # async {
+ /// let asset_bytes = include_bytes!("../tests/fixtures/cloud.jpg");
+ /// let manifest_bytes = include_bytes!("../tests/fixtures/cloud_manifest.c2pa");
+ ///
+ /// let manifest_store = ManifestStore::from_manifest_and_asset_bytes_async(manifest_bytes, asset_bytes)
+ /// .await
+ /// .unwrap();
+ ///
+ /// println!("{}", manifest_store);
+ /// # };
+ /// #
+ /// # Ok(())
+ /// }
+ /// ```
+ pub async fn from_manifest_and_asset_bytes_async(
+ manifest_bytes: &[u8],
+ asset_bytes: &[u8],
+ ) -> Result<ManifestStore> {
+ let mut validation_log = DetailedStatusTracker::new();
+ let store = Store::from_jumbf(manifest_bytes, &mut validation_log)?;
+
+ Store::verify_store_async(&store, asset_bytes, &mut validation_log).await?;
+
+ Ok(Self::from_store(&store, &mut validation_log))
+ }
}
impl Default for ManifestStore {
@@ -264,10 +297,9 @@ mod tests {
assert!(manifest.time().is_some());
}
+ #[cfg_attr(not(target_arch = "wasm32"), actix::test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
- #[ignore]
- #[allow(dead_code)]
- async fn manifest_report_image_wasm() {
+ async fn manifest_report_image_async() {
let image_bytes = include_bytes!("../tests/fixtures/CA.jpg");
let manifest_store =
@@ -292,7 +324,6 @@ mod tests {
let manifest_store = ManifestStore::from_file("tests/fixtures/CA.jpg").unwrap();
println!("{}", manifest_store);
- assert!(!manifest_store.manifests.is_empty());
assert!(manifest_store.active_label().is_some());
assert!(manifest_store.get_active().is_some());
assert!(!manifest_store.manifests().is_empty());
@@ -302,4 +333,19 @@ mod tests {
assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert");
assert!(manifest.time().is_some());
}
+
+ #[cfg_attr(not(target_arch = "wasm32"), actix::test)]
+ #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+ async fn manifest_report_from_manifest_and_asset_bytes_async() {
+ let asset_bytes = include_bytes!("../tests/fixtures/cloud.jpg");
+ let manifest_bytes = include_bytes!("../tests/fixtures/cloud_manifest.c2pa");
+
+ let manifest_store =
+ ManifestStore::from_manifest_and_asset_bytes_async(manifest_bytes, asset_bytes)
+ .await
+ .unwrap();
+ assert!(!manifest_store.manifests().is_empty());
+ assert!(manifest_store.validation_status().is_none());
+ println!("{}", manifest_store);
+ }
}
diff --git a/sdk/tests/fixtures/cloud.jpg b/sdk/tests/fixtures/cloud.jpg
Binary files differ.
diff --git a/sdk/tests/fixtures/cloud_manifest.c2pa b/sdk/tests/fixtures/cloud_manifest.c2pa
Binary files differ.