@@ -329,6 +329,58 @@ auto builder = Builder(manifest_json);
329329
330330 <TabItem value=" rust" label=" Rust" >
331331 This is how to attach and sign a manifest using Rust.
332+
333+ From [`c2pa-rs/sdk/examples/v2api.rs`](https://github.com/contentauth/c2pa-rs/blob/main/sdk/examples/v2api.rs#L88C5-L134C1):
334+
335+ ```rust
336+ let json = manifest_def(title, format);
337+
338+ let mut builder = Builder::from_json(&json)?;
339+ builder.add_ingredient_from_stream(
340+ json!({
341+ " title" : parent_name,
342+ " relationship" : " parentOf"
343+ })
344+ .to_string(),
345+ format,
346+ &mut source,
347+ )?;
348+
349+ let thumb_uri = builder
350+ .definition
351+ .thumbnail
352+ .as_ref()
353+ .map(|t| t.identifier.clone());
354+
355+ // add a manifest thumbnail ( just reuse the image for now )
356+ if let Some(uri) = thumb_uri {
357+ if !uri.starts_with(" self#jumbf" ) {
358+ source.rewind()?;
359+ builder.add_resource(&uri, &mut source)?;
360+ }
361+ }
362+
363+ // write the manifest builder to a zipped stream
364+ let mut zipped = Cursor::new(Vec::new());
365+ builder.to_archive(&mut zipped)?;
366+
367+ // write the zipped stream to a file for debugging
368+ //let debug_path = format!(" {}/../target/test.zip" , env!(" CARGO_MANIFEST_DIR" ));
369+ // std::fs::write(debug_path, zipped.get_ref())?;
370+
371+ // unzip the manifest builder from the zipped stream
372+ zipped.rewind()?;
373+
374+ let ed_signer =
375+ |_context: *const (), data: &[u8]| CallbackSigner::ed25519_sign(data, PRIVATE_KEY);
376+ let signer = CallbackSigner::new(ed_signer, SigningAlg::Ed25519, CERTS);
377+
378+ let mut builder = Builder::from_archive(&mut zipped)?;
379+ // sign the ManifestStoreBuilder and write it to the output stream
380+ let mut dest = Cursor::new(Vec::new());
381+ builder.sign(&signer, format, &mut source, &mut dest)?;
382+ ```
383+
332384 </TabItem>
333385
334386</Tabs>
0 commit comments