Documentation
¶
Overview ¶
Package lib provides Go bindings for the c2pa-rs Content Authenticity SDK.
The package exposes the C2PA reader, builder, signer, settings and context APIs through cgo so Go programs can read, create and sign C2PA manifests on any asset format that c2pa-rs supports (JPEG, PNG, TIFF, MP4, and others).
All operations are scoped to a Context. A context optionally carries Settings (trust list, verification policy, builder defaults, etc.). Create a context either with NewContext for defaults, or via NewContextBuilder when you need to attach settings:
ctx, err := lib.NewContext()
if err != nil { ... }
defer ctx.Close()
Reading manifests ¶
Use ReaderFromFile (or NewReader with a stream) to inspect manifests embedded in or accompanying an asset:
r, err := lib.ReaderFromFile(ctx, "signed.jpg")
if err != nil { ... }
defer r.Close()
fmt.Println(r.Json())
Signing assets ¶
Implement the Signer interface (or wrap your own signing callback) and drive Builder.Sign:
b, err := lib.BuilderFromJson(ctx, manifestJson)
if err != nil { ... }
defer b.Close()
manifest, err := b.Sign("in.jpg", "out.jpg", signer)
The Builder type mirrors the upstream API, including SetIntent, SetRemoteUrl, AddAction, AddResource, AddIngredient, and archive helpers.
Linking ¶
This package links against the c2pa_c shared/static library built from the c2pa-rs c2pa_c_ffi crate. See the project README for build instructions.
Index ¶
- func C2paError() string
- func CpaVersion() string
- func GoSignerCallback(context C.uintptr_t, input *C.uint8_t, input_size C.uintptr_t, ...) C.intptr_t
- func StreamFlush(context C.uintptr_t) C.intptr_t
- func StreamRead(context C.uintptr_t, buffer *C.uint8_t, size C.intptr_t) C.intptr_t
- func StreamSeek(context C.uintptr_t, offset C.intptr_t, mode C.C2paSeekMode) C.intptr_t
- func StreamWrite(context C.uintptr_t, buffer *C.uint8_t, size C.intptr_t) C.intptr_t
- type Builder
- func BuilderFromArchive(ctx *Context, file *os.File) (*Builder, error)
- func BuilderFromArchiveFile(ctx *Context, path string) (*Builder, error)
- func BuilderFromDefinition(ctx *Context, def *schema.ManifestDefinition) (*Builder, error)
- func BuilderFromJson(ctx *Context, json string) (*Builder, error)
- func NewBuilder(ctx *Context) (*Builder, error)
- func (b *Builder) AddAction(actionJson string) error
- func (b *Builder) AddActionTyped(action any) error
- func (b *Builder) AddIngredientFromFile(ingredientJson string, path string) error
- func (b *Builder) AddIngredientFromStream(ingredientJson string, format string, file *os.File) error
- func (b *Builder) AddResource(uri string, file *os.File) error
- func (b *Builder) AddResourceFromFile(uri string, path string) error
- func (b *Builder) Close()
- func (b *Builder) SetBasePath(path string) error
- func (b *Builder) SetIntent(intent BuilderIntent, digitalSourceType DigitalSourceType) error
- func (b *Builder) SetNoEmbed()
- func (b *Builder) SetRemoteUrl(url string) error
- func (b *Builder) Sign(input_file string, output_file string, signer Signer) ([]byte, error)
- func (b *Builder) ToArchive(file *os.File) error
- func (b *Builder) ToArchiveFile(path string) error
- type BuilderIntent
- type Context
- type ContextBuilder
- type DigitalSourceType
- type Reader
- func (r *Reader) Close()
- func (r *Reader) DetailedJson() string
- func (r *Reader) DetailedManifest() (*schema.ManifestStore, error)
- func (r *Reader) IsEmbedded() bool
- func (r *Reader) Json() string
- func (r *Reader) Manifest() (*schema.ManifestStore, error)
- func (r *Reader) Ptr() *C.C2paReader
- func (r *Reader) RemoteUrl() string
- func (r *Reader) ResourceToFile(uri string, path string) (int64, error)
- func (r *Reader) ResourceToStream(uri string, file *os.File) (int64, error)
- type Settings
- type Signer
- type SignerAdapter
- type SigningAlg
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CpaVersion ¶
func CpaVersion() string
CpaVersion returns the version string from the c2pa library.
func GoSignerCallback ¶
func StreamRead ¶
func StreamSeek ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder wraps a C C2paBuilder*. It holds the underlying C pointer and provides a place to attach methods that operate on the C Builder.
func BuilderFromArchive ¶
BuilderFromArchive creates a Builder from an archive previously produced by ToArchive, using the supplied Context.
func BuilderFromArchiveFile ¶
BuilderFromArchiveFile is a convenience wrapper around BuilderFromArchive.
func BuilderFromDefinition ¶ added in v0.83.1
func BuilderFromDefinition(ctx *Context, def *schema.ManifestDefinition) (*Builder, error)
BuilderFromDefinition creates a Builder from a typed ManifestDefinition. It marshals the definition to JSON and forwards it to BuilderFromJson.
func BuilderFromJson ¶
BuilderFromJson creates a Builder from the given JSON manifest definition using the supplied Context.
func NewBuilder ¶
NewBuilder creates a new Builder from the given Context.
func (*Builder) AddActionTyped ¶ added in v0.83.1
AddActionTyped marshals action to JSON and adds it as an action assertion.
func (*Builder) AddIngredientFromFile ¶
AddIngredientFromFile is a convenience wrapper that opens path and adds it as an ingredient, deriving the format from the file extension.
func (*Builder) AddIngredientFromStream ¶
func (b *Builder) AddIngredientFromStream(ingredientJson string, format string, file *os.File) error
AddIngredientFromStream adds an ingredient described by ingredientJson, read from file with the given format (mime type or file extension).
func (*Builder) AddResource ¶
AddResource adds a resource read from file under the given URI identifier.
func (*Builder) AddResourceFromFile ¶
AddResourceFromFile is a convenience wrapper that opens path and adds it as a resource.
func (*Builder) SetBasePath ¶
SetBasePath sets the directory used to resolve resources not found in memory.
func (*Builder) SetIntent ¶
func (b *Builder) SetIntent(intent BuilderIntent, digitalSourceType DigitalSourceType) error
SetIntent sets the builder intent. digitalSourceType is required for IntentCreate and ignored for other intents.
func (*Builder) SetNoEmbed ¶
func (b *Builder) SetNoEmbed()
func (*Builder) SetRemoteUrl ¶
SetRemoteUrl sets the remote URL that will be embedded into the asset on signing.
func (*Builder) ToArchiveFile ¶
ToArchiveFile is a convenience wrapper that creates path and writes the builder archive to it.
type BuilderIntent ¶
type BuilderIntent C.C2paBuilderIntent
BuilderIntent corresponds to C2paBuilderIntent.
const ( IntentCreate BuilderIntent = C.Create IntentEdit BuilderIntent = C.Edit IntentUpdate BuilderIntent = C.Update )
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context wraps an immutable C2paContext*. A Context is shareable and may be used to create multiple Reader and Builder instances.
func NewContext ¶
NewContext creates a new immutable Context with default settings.
func (*Context) Cancel ¶
Cancel requests cancellation of any in-progress operation on this context. Thread-safe.
func (*Context) Close ¶
func (c *Context) Close()
Close releases the underlying C context. Safe to call once; subsequent calls are no-ops.
func (*Context) Ptr ¶
func (c *Context) Ptr() *C.C2paContext
Ptr returns the underlying C pointer. Use carefully; callers must not keep the pointer past the lifetime of the Context.
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder wraps a C2paContextBuilder*. It is consumed by Build().
func NewContextBuilder ¶
func NewContextBuilder() (*ContextBuilder, error)
NewContextBuilder creates a new context builder with default settings.
func (*ContextBuilder) Build ¶
func (b *ContextBuilder) Build() (*Context, error)
Build consumes the builder and returns an immutable Context.
func (*ContextBuilder) Close ¶
func (b *ContextBuilder) Close()
Close releases the underlying builder if it has not been consumed by Build.
func (*ContextBuilder) SetSettings ¶
func (b *ContextBuilder) SetSettings(settings *Settings) error
SetSettings configures the builder with the given settings. Settings are cloned internally; the caller retains ownership and should still Close() it.
func (*ContextBuilder) SetSigner ¶
func (b *ContextBuilder) SetSigner(signer *SignerAdapter) error
SetSigner attaches a signer to the context. The builder takes ownership of the underlying C signer; the SignerAdapter's pointer is cleared so its Close() will not double-free it. The Go-side handle is still released when the SignerAdapter is closed.
type DigitalSourceType ¶
type DigitalSourceType C.C2paDigitalSourceType
DigitalSourceType corresponds to C2paDigitalSourceType.
const ( SourceEmpty DigitalSourceType = C.Empty SourceTrainedAlgorithmicData DigitalSourceType = C.TrainedAlgorithmicData SourceDigitalCapture DigitalSourceType = C.DigitalCapture SourceComputationalCapture DigitalSourceType = C.ComputationalCapture SourceNegativeFilm DigitalSourceType = C.NegativeFilm SourcePositiveFilm DigitalSourceType = C.PositiveFilm SourcePrint DigitalSourceType = C.Print SourceHumanEdits DigitalSourceType = C.HumanEdits SourceCompositeWithTrainedAlgorithmicMedia DigitalSourceType = C.CompositeWithTrainedAlgorithmicMedia SourceAlgorithmicallyEnhanced DigitalSourceType = C.AlgorithmicallyEnhanced SourceDigitalCreation DigitalSourceType = C.DigitalCreation SourceDataDrivenMedia DigitalSourceType = C.DataDrivenMedia SourceTrainedAlgorithmicMedia DigitalSourceType = C.TrainedAlgorithmicMedia SourceAlgorithmicMedia DigitalSourceType = C.AlgorithmicMedia SourceScreenCapture DigitalSourceType = C.ScreenCapture SourceVirtualRecording DigitalSourceType = C.VirtualRecording SourceComposite DigitalSourceType = C.Composite SourceCompositeCapture DigitalSourceType = C.CompositeCapture SourceCompositeSynthetic DigitalSourceType = C.CompositeSynthetic )
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps a C C2paReader*. It holds the underlying C pointer and provides a place to attach methods that operate on the C reader.
func NewReader ¶
NewReader creates a new Reader from the given Context. The reader must be configured with a stream (e.g. via ReaderFromFile or by reusing the Context with another helper) before it can be used.
func ReaderFromFile ¶
ReaderFromFile creates a Reader by opening the given file path using the supplied Context. Returns an error if the reader could not be created.
func (*Reader) DetailedJson ¶
DetailedJson returns a detailed JSON description of the manifest store.
func (*Reader) DetailedManifest ¶ added in v0.83.1
func (r *Reader) DetailedManifest() (*schema.ManifestStore, error)
DetailedManifest returns the detailed manifest store parsed into the typed schema.ManifestStore representation.
func (*Reader) IsEmbedded ¶
IsEmbedded reports whether the reader was created from an embedded manifest.
func (*Reader) Manifest ¶ added in v0.83.1
func (r *Reader) Manifest() (*schema.ManifestStore, error)
Manifest returns the manifest store parsed into the typed schema.ManifestStore representation.
func (*Reader) Ptr ¶
func (r *Reader) Ptr() *C.C2paReader
Ptr returns the underlying C pointer. Use carefully; callers must not keep the pointer past the lifetime of the Reader or the underlying C resource.
func (*Reader) RemoteUrl ¶
RemoteUrl returns the remote URL the manifest was obtained from, or an empty string if the manifest was not remote.
func (*Reader) ResourceToFile ¶
ResourceToFile writes the resource identified by uri to the given path.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings wraps a C2paSettings*. It is used to configure a ContextBuilder via ContextBuilder.SetSettings.
func NewSettings ¶
NewSettings creates a new Settings with defaults.
func (*Settings) Close ¶
func (s *Settings) Close()
Close releases the underlying C settings. Safe to call multiple times.
func (*Settings) SetValue ¶
SetValue sets a single configuration value using dot notation. The value must be a JSON-encoded scalar or array (e.g. "true", "42", "\"ps256\"").
func (*Settings) UpdateFrom ¶ added in v0.83.1
UpdateFrom applies a typed schema.Settings value by marshaling it to JSON and calling UpdateFromString.
func (*Settings) UpdateFromString ¶
UpdateFromString loads settings from a JSON or TOML string. The format argument must be "json" or "toml".
type SignerAdapter ¶
type SignerAdapter struct {
// contains filtered or unexported fields
}
func NewSigner ¶
func NewSigner(signer Signer) (*SignerAdapter, error)
func (*SignerAdapter) Close ¶
func (s *SignerAdapter) Close()
type SigningAlg ¶
type SigningAlg C.C2paSigningAlg
const ( SigningAlgPs256 SigningAlg = C.Ps256 SigningAlgPs384 SigningAlg = C.Ps384 SigningAlgPs512 SigningAlg = C.Ps512 SigningAlgEs256 SigningAlg = C.Es256 SigningAlgEs384 SigningAlg = C.Es384 SigningAlgEs512 SigningAlg = C.Es512 C2paSigningAlgEd25519 SigningAlg = C.Ed25519 )