Skip to content

Commit

Permalink
Consolidate test signer fixture code
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten-adobe committed May 22, 2024
1 parent ab24406 commit 459118c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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)
Expand All @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<dyn Signer> {
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()
}

0 comments on commit 459118c

Please sign in to comment.