contentauth / c2pa-python

Python binding for c2pa-rs library
Apache License 2.0
23 stars 7 forks source link

proof-of-concept: go library #27

Open iameli opened 1 month ago

iameli commented 1 month ago

This is a working proof-of-concept of using NordSecurity/uniffi-bindgen-go to generate Go bindings the same way the Python ones are generated. Running make will generate a demo file that will display embedded C2PA manifests:

./dist/go-demo ~/testvids/screenshot-signed.jpg
{
  "active_manifest": "urn:uuid:019cfdc5-8d91-4b2a-bb0d-f94afb9badef",
  "manifests": {
    "urn:uuid:019cfdc5-8d91-4b2a-bb0d-f94afb9badef": {
      "claim_generator": "Aquareum c2patool/0.9.6 c2pa-rs/0.33.1",
[ ... ]

Some notes:

  1. I had to bump to uniffi = "0.25.0" to match the expected version for uniffi-bindgen-go. Doing so required this change, which I do not understand in the slightest, but it got it compiling:
    
    diff --git a/src/streams.rs b/src/streams.rs
    index 960c9b4..62001e0 100644
    --- a/src/streams.rs
    +++ b/src/streams.rs
    @@ -51,6 +51,10 @@ impl Stream for Box<dyn Stream> {
     }
    }

+unsafe impl uniffi::LiftRef for Box {

  1. I'm not really sure of the best way to get this into the hands of Go developers. Unlike Python, we can't just distribute prebuilt libraries as wheels, so I think inevitably there's going to be a cargo build step somewhere in any projects that make use of this. Not a problem for my use case exactly, but worth contemplating. Maybe it could be as simple as a single cargo install command that you have to run once to get the dependency in place?
  2. I'm making use of the same Stream primitives as the Python library, using a Go implementation of the interface at pkg/c2pa/c2pa.go. I don't really know if this is wise or unwise, but if it's actually useful maybe those primitives could be moved to an upstream library so they wouldn't be duplicated in the Python and Go examples.
  3. I changed crate-type = ["cdylib"] to crate-type = ["staticlib"] which seems like a better fit for Go's single-binary output.