Skip to content

[1] Feat: Add context, settings, and JSON APIs#47

Open
redaranj wants to merge 1 commit intocontentauth:mainfrom
redaranj:feature/context-settings-api
Open

[1] Feat: Add context, settings, and JSON APIs#47
redaranj wants to merge 1 commit intocontentauth:mainfrom
redaranj:feature/context-settings-api

Conversation

@redaranj
Copy link
Member

@redaranj redaranj commented Mar 5, 2026

Changes in this pull request

  • Updates native library to v0.75.19.
  • Adds new context and settings APIs from the underlying library
  • Adds C2PAJson for centralized JSON serialization
  • Adds SettingsValidator for validating C2PA settings

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • All applicable changes have been documented
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 90.45346% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.33%. Comparing base (16dcd0b) to head (22a7f35).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ary/src/main/kotlin/org/contentauth/c2pa/Reader.kt 37.50% 8 Missing and 2 partials ⚠️
...ry/src/main/kotlin/org/contentauth/c2pa/Builder.kt 80.85% 5 Missing and 4 partials ⚠️
...org/contentauth/c2pa/manifest/SettingsValidator.kt 97.12% 4 Missing and 4 partials ⚠️
...c/main/kotlin/org/contentauth/c2pa/C2PASettings.kt 66.66% 2 Missing and 4 partials ⚠️
...ary/src/main/kotlin/org/contentauth/c2pa/Stream.kt 85.18% 1 Missing and 3 partials ⚠️
...rc/main/kotlin/org/contentauth/c2pa/C2PAContext.kt 78.57% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #47      +/-   ##
============================================
+ Coverage     59.82%   68.33%   +8.51%     
  Complexity        9        9              
============================================
  Files            52       57       +5     
  Lines          1558     1936     +378     
  Branches        162      267     +105     
============================================
+ Hits            932     1323     +391     
+ Misses          526      496      -30     
- Partials        100      117      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redaranj redaranj force-pushed the feature/context-settings-api branch from f43629c to 3e2acab Compare March 12, 2026 10:34
Introduce C2PAContext and C2PASettings for shared configuration across
readers and builders. Add C2PAJson for centralized JSON serialization.
Add SettingsValidator for validating C2PA settings. Rewrite Builder to
use context-based creation flow. Add Reader context support with
withStream and withFragment. Update native library to v0.75.19.
@redaranj redaranj force-pushed the feature/context-settings-api branch from 3e2acab to 22a7f35 Compare March 12, 2026 19:11
import org.contentauth.c2pa.SigningAlgorithm

/**
* Validates C2PA settings JSON/TOML for schema compliance and provides warnings for common issues.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool, but … it's at risk of getting out of date as we evolve the set of settings. Is there a straightforward way to track such changes?

Copy link
Member Author

@redaranj redaranj Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scouten-adobe Perhaps I could extend the current CI c2pa-rs version check (or maybe better, add another scheduled job), that checks for changes in specific files (FFI, settings, etc) and alerts or opens a PR when something new is detected.

Overall, this brings up an issue that I'm working through: where is the line where I defer to c2pa-rs? My general goal has been that devs can look just at the mobile library (not c2pa-rs or the spec) and understand what's possible. The options I considered here are:

  • accept any settings string and pass it straight through, refer users to c2pa-rs docs for details (no maintenance, but not great developer experience)
  • same thing, but include docs on the currently available settings (light maintenance)
  • create a struct that mirrors the shape of the settings and require that as an argument everywhere (very nice, informative developer experience, but creates a hard requirement to update the struct when the allowable settings change)
  • middle path 1: create the struct, but accept string settings everywhere, users can either pass a raw string or a serialized struct (requires maintenance, but doesn't block people from adopting new settings if the struct hasn't been updated)
  • middle path 2: accept raw settings string, but give users a way to validate their structure against the current schema (similar tradeoffs as previous one)

Let me know if you have a preference here. This issue will come up again in a subsequent PR where we have created a similar manifest validator.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my preference is for your "middle path 1" but I'll ask a couple other people on the team for their opinions as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our JS APIs we added a tool that generates JSON schema and we generated the client side apis using htat. You could leverage the schema to validate and update it whenever it changes.

* @see ManifestValidator
* @see SettingsValidator
*/
data class ValidationResult(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class should have a different name since "validation result" has a specific meaning in C2PA: https://spec.c2pa.org/specifications/specifications/2.3/specs/C2PA_Specification.html#_returning_validation_results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I will rename it.

@scouten-adobe
Copy link

@redaranj I finished reading the PR and have no further comments; ping me when you're ready for re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants