#[cfg(feature = "file_io")]
mod integration_1 {
use c2pa::{
assertions::{c2pa_action, Action, Actions},
create_signer, Ingredient, Manifest, ManifestStore, Result, Signer, SigningAlg,
};
use std::path::PathBuf;
use tempfile::tempdir;
const GENERATOR: &str = "app";
fn get_temp_signer() -> Box<dyn Signer> {
let mut signcert_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
signcert_path.push("tests/fixtures/certs/ps256.pub");
let mut pkey_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
pkey_path.push("tests/fixtures/certs/ps256.pem");
create_signer::from_files(signcert_path, pkey_path, SigningAlg::Ps256, None)
.expect("get_signer_from_files")
}
#[test]
#[cfg(feature = "file_io")]
fn test_embed_manifest() -> Result<()> {
let dir = tempdir()?;
let output_path = dir.path().join("test_file.jpg");
let mut parent_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
parent_path.push("tests/fixtures/earth_apollo17.jpg");
let mut ingredient_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
ingredient_path.push("tests/fixtures/libpng-test.png");
let mut manifest = Manifest::new(GENERATOR.to_owned());
let mut actions = Actions::new();
let parent = Ingredient::from_file(&parent_path)?;
actions = actions.add_action(
Action::new(c2pa_action::EDITED)
.set_parameter("name".to_owned(), "import")?
.set_parameter("identifier".to_owned(), parent.instance_id().to_owned())?,
);
manifest.set_parent(parent)?;
actions = actions.add_action(
Action::new("c2pa.edit").set_parameter("name".to_owned(), "brightnesscontrast")?,
);
let ingredient = Ingredient::from_file(&ingredient_path)?;
actions = actions.add_action(
Action::new(c2pa_action::EDITED)
.set_parameter("name".to_owned(), "import")?
.set_parameter("identifier".to_owned(), ingredient.instance_id().to_owned())?,
);
manifest.add_ingredient(ingredient);
manifest.add_assertion(&actions)?;
let signer = get_temp_signer();
manifest.embed(&parent_path, &output_path, &*signer)?;
let manifest_store = ManifestStore::from_file(&output_path)?;
println!("{}", manifest_store);
assert!(manifest_store.get_active().is_some());
if let Some(manifest) = manifest_store.get_active() {
assert!(manifest.title().is_some());
assert_eq!(manifest.ingredients().len(), 2);
} else {
panic!("no manifest in store");
}
Ok(())
}
}