use c2pa::{Assertion, AssertionBase, AssertionCbor, Manifest, Result};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Custom {
pub version: String,
}
impl Custom {
pub fn new() -> Self {
Self {
version: c2pa::VERSION.to_owned(),
}
}
}
impl Default for Custom {
fn default() -> Self {
Self::new()
}
}
impl AssertionCbor for Custom {}
impl AssertionBase for Custom {
const LABEL: &'static str = "org.contentauth.custom";
fn to_assertion(&self) -> c2pa::Result<Assertion> {
Self::to_cbor_assertion(self)
}
fn from_assertion(assertion: &Assertion) -> Result<Self> {
Self::from_cbor_assertion(assertion)
}
}
fn main() -> Result<()> {
let mut manifest = Manifest::new("c2pa-rs".to_owned());
let original = Custom::new();
manifest.add_assertion(&original)?;
let result: Custom = manifest.find_assertion(Custom::LABEL)?;
println!("{}\n", manifest);
println!("c2pa sdk version = {}", result.version);
Ok(())
}
#[cfg(test)]
pub mod tests {
#![allow(clippy::expect_used)]
use super::*;
#[test]
fn assertion_custom() {
let mut manifest = Manifest::new("my_app".to_owned());
let original = Custom::new();
manifest.add_assertion(&original).expect("adding assertion");
println!("{}", manifest);
let result: Custom = manifest
.find_assertion(Custom::LABEL)
.expect("find_assertion");
assert_eq!(original.version, result.version);
}
}