Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ crate-type = ["lib", "cdylib"]
normal = ["openssl-src"]

[dependencies]
c2pa = {version = "0.40.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]}
c2pa = { version = "0.41.1", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]}
c2pa-crypto = {version = "0.3.1" }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are needed, c2pa-crypto and c2pa

thiserror = "1.0.49"
uniffi = "0.28.2"
openssl-src = "=300.3.1" # Required for openssl-sys
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
maturin==1.7.4
uniffi-bindgen==0.28.0
cryptography==43.0.1
cryptography==44.0.0
pytest==8.3.4
41 changes: 41 additions & 0 deletions src/callback_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// each license.

use c2pa::{Signer, SigningAlg};
// RawSigner is currently used only fully qualified
use c2pa_crypto::{raw_signature::RawSignerError, time_stamp::TimeStampProvider};
use log::debug;

use crate::Result;
Expand All @@ -34,6 +36,41 @@ pub struct RemoteSigner {
reserve_size: u32,
}

impl TimeStampProvider for RemoteSigner {}

impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner {
fn sign(&self, data: &[u8]) -> std::result::Result<Vec<u8>, RawSignerError> {
let signature_result = self.signer_callback.sign(data.to_vec());

match signature_result {
Ok(signature) => Ok(signature),
Err(e) => Err(c2pa_crypto::raw_signature::RawSignerError::IoError(
e.to_string(),
)),
}
}

fn alg(&self) -> c2pa_crypto::raw_signature::SigningAlg {
match self.alg {
SigningAlg::Es384 => c2pa_crypto::raw_signature::SigningAlg::Es384,
SigningAlg::Es512 => c2pa_crypto::raw_signature::SigningAlg::Es512,
SigningAlg::Ps256 => c2pa_crypto::raw_signature::SigningAlg::Ps256,
SigningAlg::Ps384 => c2pa_crypto::raw_signature::SigningAlg::Ps384,
SigningAlg::Ps512 => c2pa_crypto::raw_signature::SigningAlg::Ps512,
SigningAlg::Ed25519 => c2pa_crypto::raw_signature::SigningAlg::Ed25519,
SigningAlg::Es256 => c2pa_crypto::raw_signature::SigningAlg::Es256,
}
}

fn cert_chain(&self) -> std::result::Result<Vec<Vec<u8>>, RawSignerError> {
Ok(Vec::new())
}

fn reserve_size(&self) -> usize {
self.reserve_size as usize
}
}

impl Signer for RemoteSigner {
fn sign(&self, data: &[u8]) -> c2pa::Result<Vec<u8>> {
self.signer_callback
Expand All @@ -57,6 +94,10 @@ impl Signer for RemoteSigner {
fn direct_cose_handling(&self) -> bool {
true
}

fn raw_signer(&self) -> Box<&dyn c2pa_crypto::raw_signature::RawSigner> {
Box::new(self)
}
}

impl CallbackSigner {
Expand Down
Loading