-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,603 additions
and
426 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "teddybear-c2pa" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
categories.workspace = true | ||
|
||
[dependencies] | ||
c2pa = { git = "https://github.com/vaultie/c2pa-rs", features = ["unstable_api"] } | ||
ed25519-dalek = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::io::{Read, Seek, Write}; | ||
|
||
use c2pa::{Builder, Signer, SigningAlg}; | ||
use ed25519_dalek::{Signer as _, SigningKey}; | ||
|
||
pub use c2pa::ManifestDefinition; | ||
|
||
pub struct Ed25519Signer { | ||
key: SigningKey, | ||
certificates: Vec<Vec<u8>>, | ||
} | ||
|
||
impl Ed25519Signer { | ||
pub fn new(key: SigningKey, certificate: Vec<u8>) -> Self { | ||
Self { | ||
key, | ||
certificates: vec![certificate], | ||
} | ||
} | ||
} | ||
|
||
impl Signer for Ed25519Signer { | ||
#[inline] | ||
fn sign(&self, data: &[u8]) -> c2pa::Result<Vec<u8>> { | ||
Ok(self.key.sign(data).to_vec()) | ||
} | ||
|
||
#[inline] | ||
fn alg(&self) -> SigningAlg { | ||
SigningAlg::Ed25519 | ||
} | ||
|
||
#[inline] | ||
fn certs(&self) -> c2pa::Result<Vec<Vec<u8>>> { | ||
Ok(self.certificates.clone()) | ||
} | ||
|
||
#[inline] | ||
fn reserve_size(&self) -> usize { | ||
2048 | ||
} | ||
} | ||
|
||
pub fn embed_manifest<R: Read + Seek + Send, W: Write + Read + Seek + Send, S: Signer>( | ||
source: &mut R, | ||
dest: &mut W, | ||
format: &str, | ||
definition: ManifestDefinition, | ||
signer: &S, | ||
) -> c2pa::Result<Vec<u8>> { | ||
let mut builder = Builder::default(); | ||
builder.definition = definition; | ||
builder.sign(signer, format, source, dest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PrivateEd25519 } from '@vaultie/teddybear' | ||
import { readFileSync } from 'fs' | ||
import { describe, it } from 'vitest' | ||
|
||
const image = readFileSync(process.env.placeholderImage!) | ||
const certificate = readFileSync(process.env.certificate!) | ||
|
||
describe('can execute C2PA operations', () => { | ||
it('can sign a C2PA manifest', async () => { | ||
// This key should correspond to the certificate private key | ||
const keyBytes = Buffer.from("5ff5e2393a44256abe197c82742366ff2f998f6822980e726f8fd16d6bd07eb1", "hex"); | ||
|
||
const key = await PrivateEd25519.fromBytes(new Uint8Array(keyBytes)); | ||
|
||
key.embedC2PAManifest(new Uint8Array(certificate), new Uint8Array(image), 'image/jpeg', { | ||
title: 'Hello World', | ||
claim_generator_info: [ | ||
{ name: "Teddybear" } | ||
] | ||
}) | ||
}) | ||
}) |