atlas_cli/manifest/
signer.rs

1use crate::error::{Error, Result};
2use crate::signing;
3use crate::signing::signable::Signable;
4use atlas_c2pa_lib::cose::HashAlgorithm;
5use atlas_c2pa_lib::manifest::Manifest;
6use base64::Engine;
7use base64::engine::general_purpose::STANDARD;
8use std::path::PathBuf;
9
10impl Signable for Manifest {
11    fn sign(&mut self, key_path: PathBuf, hash_alg: HashAlgorithm) -> Result<()> {
12        let private_key = signing::load_private_key(&key_path)?;
13
14        // Serialize claim to CBOR for signing
15        let claim_cbor =
16            serde_cbor::to_vec(&self.claim).map_err(|e| Error::Serialization(e.to_string()))?;
17
18        // Use the signing module with the specified algorithm
19        let signature = signing::sign_data_with_algorithm(&claim_cbor, &private_key, &hash_alg)?;
20
21        // Add signature to claim
22        self.claim.signature = Some(STANDARD.encode(&signature));
23
24        Ok(())
25    }
26}