From 459118c6f87779bdb74e65345f59b35cd2f27eee Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Wed, 22 May 2024 16:02:12 -0700 Subject: [PATCH] Consolidate test signer fixture code --- src/tests/builder.rs | 18 ++++++------------ src/tests/fixtures/mod.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/tests/builder.rs b/src/tests/builder.rs index f950789..4a40cb4 100644 --- a/src/tests/builder.rs +++ b/src/tests/builder.rs @@ -13,12 +13,12 @@ use std::fs::OpenOptions; -use c2pa::{create_signer, Manifest, ManifestStore, SigningAlg}; +use c2pa::{Manifest, ManifestStore}; use crate::{ builder::{IdentityAssertionBuilder, ManifestBuilder}, internal::naive_credential_handler::NaiveCredentialHolder, - tests::fixtures::{fixture_path, temp_dir_path}, + tests::fixtures::{fixture_path, temp_c2pa_signer, temp_dir_path}, IdentityAssertion, }; @@ -27,19 +27,13 @@ async fn simple_case() { // TO DO: Clean up code and extract into builder interface. // For now, just looking for a simple proof-of-concept. - let signcert_path = fixture_path("certs/ps256.pub"); - let pkey_path = fixture_path("certs/ps256.pem"); - - let signer = - create_signer::from_files(signcert_path, pkey_path, SigningAlg::Ps256, None).unwrap(); - let source = fixture_path("cloud.jpg"); + let mut input_stream = OpenOptions::new().read(true).open(&source).unwrap(); + let temp_dir = tempfile::tempdir().unwrap(); let dest = temp_dir_path(&temp_dir, "cloud_output.jpg"); - let mut input_stream = OpenOptions::new().read(true).open(&source).unwrap(); - let mut output_stream = OpenOptions::new() .read(true) .write(true) @@ -48,16 +42,16 @@ async fn simple_case() { .open(&dest) .unwrap(); - let manifest: Manifest = Manifest::new("identity_test/simple_case"); - // TO DO: Add a metadata assertion as an example. let naive_credential = NaiveCredentialHolder {}; let iab = IdentityAssertionBuilder::for_credential_holder(naive_credential); + let signer = temp_c2pa_signer(); let mut mb = ManifestBuilder::default(); mb.add_assertion(iab); + let manifest: Manifest = Manifest::new("identity_test/simple_case"); mb.build( manifest, "jpg", diff --git a/src/tests/fixtures/mod.rs b/src/tests/fixtures/mod.rs index 8eea7ad..30326a4 100644 --- a/src/tests/fixtures/mod.rs +++ b/src/tests/fixtures/mod.rs @@ -17,6 +17,7 @@ use std::{env, path::PathBuf}; +use c2pa::{create_signer, Signer, SigningAlg}; use tempfile::TempDir; pub(crate) fn fixture_path(name: &str) -> PathBuf { @@ -36,3 +37,10 @@ pub(crate) fn temp_dir_path(temp_dir: &TempDir, file_name: &str) -> PathBuf { path.push(file_name); path } + +pub(crate) fn temp_c2pa_signer() -> Box { + let sign_cert = include_bytes!("../../tests/fixtures/certs/ps256.pub").to_vec(); + let pem_key = include_bytes!("../../tests/fixtures/certs/ps256.pem").to_vec(); + + create_signer::from_keys(&sign_cert, &pem_key, SigningAlg::Ps256, None).unwrap() +}