Skip to content

feat!: adopt c2pa-swift 0.1.0 and c2pa-android 0.1.2 - #8

Merged
redaranj merged 1 commit into
mainfrom
feat/sync-with-c2pa-swift-android-0-1-x-apis
Nov 30, 2026
Merged

redaranj merged 1 commit into
mainfrom
feat/sync-with-c2pa-swift-android-0-1-x-apis

Conversation

@redaranj

Copy link
Copy Markdown
Collaborator

Stacked on #6.

This brings c2pa-flutter up to date with c2pa-swift 0.1.0 (c2pa-rs 0.92.0) and c2pa-android 0.1.2 (c2pa-rs 0.92.2), the latest release of each. It also moves the Dart/native boundary to Pigeon, adds typed errors, and runs the whole integration suite on both platforms in CI. It replaces #7, whose fixes it includes.

Upstream changes and how the plugin follows them

Both SDKs dropped global settings: all configuration now lives on a context, which can also carry a signer, a progress callback, cancellation and an HTTP resolver. The plugin is rebuilt around that model.

  • Contexts: C2paContext.create(settings:, signer:, onProgress:, httpResolver:) and cancel(). NativeHttpResolver uses URLSession / OkHttp; CallbackHttpResolver answers the SDK's requests from Dart. C2pa.loadSettings keeps working by applying its settings to readers and builders created without a context.
  • Builder: sign() without a signer uses the context signer. Also new: signFile() (streams files natively), setBasePath(), ingredient archives, the embeddable flow (placeholder, setDataHashExclusions, updateHashFromBytes/File, signEmbeddable, hashType, BMFF setFixedSizeMerkle / hashMdatBytes) and C2pa.composeManifest().
  • Reader: crJSON, readFileWithManifest / readBytesWithManifest, readFragment (Android), an optional context, and MIME type lists from the SDKs.
  • Signers: CawgIdentitySigner wraps a claim signer and an X.509 identity signer.
  • iOS gaps closed: createCSR, importKey and enrollHardwareKey now work. The IPTC source types c2pa-swift does not model are recorded instead of falling back to digitalCapture.
  • Removed with the SDKs: readIngredientFromFile, ReaderOptions.dataDir, and the hashed-signing trio.

Where the SDKs differ, the Dart API exposes the union and fails with NOT_IMPLEMENTED_<PLATFORM>; the README has the table.

Dart API

  • Every failure is a sealed C2paException: manifest not found, cancelled, SDK error, invalid argument, unsupported, key error or platform error. Reading an asset without a manifest throws C2paManifestNotFoundException, as both SDKs do, and the read methods return non-nullable types.
  • Builder calls run in call order even when they are not awaited. setIntent, setNoEmbed, setRemoteUrl, addAction and every dispose() return futures, and finalizers release handles that are garbage collected undisposed.
  • ValidationStatus gains trusted from the SDK's validation_state.
  • Also: setValue takes JSON values, enrollHardwareKey returns a typed result, and IngredientInfo.activeManifest links ingredients to their manifests.
  • Stricter analysis is on: strict casts, inference and raw types, unawaited_futures, discarded_futures and avoid_dynamic_calls.

Native side

  • pigeons/c2pa_api.dart defines the interface, and Pigeon 30.0.2 generates typed Dart, Kotlin and Swift bindings. CI fails if the generated files drift from the definition.
  • Each plugin runs SDK calls on one serial worker, in the order Dart sent them, with key management on a separate pool. Callback signers, progress and Dart HTTP resolvers call back to Dart while the worker waits, so nothing blocks the UI, and a builder is never freed under a running call.
  • Fixed:
    • addIngredientFromFile used the wrong argument key and never worked.
    • Android truncates an existing destination, and a missing input file is an error.
    • Android action parameters keep their types, and Android honours detailed.
    • iOS applies the same default created_assertion_labels as Android, so the same manifest records the same assertions as created on both platforms.
    • createKey honours its algorithm.
    • iOS exportPublicKey returns a SubjectPublicKeyInfo, keychain keys are tagged the way c2pa-swift looks them up, and deleteKey actually deletes keychain keys.
    • claimGenerator reads v2 claims.

Toolchain

  • Dart 3.13 / Flutter 3.47 or later; CI pins Flutter 3.47.9.
  • iOS needs Xcode 26.4+ (c2pa-swift declares Swift tools 6.3), and the iOS CI jobs run on macos-26.
  • Android needs compileSdk 36.

Tests

  • Unit tests: 307. test/c2pa_pigeon_test.dart drives PigeonC2pa through a fake host API, covering:
    • call ordering
    • signer messages and callback lifetimes
    • the native-to-Dart callbacks
    • error mapping
  • Integration tests: every file in example/integration_test/ now runs in CI on an iOS simulator and an Android emulator. The new sdk_parity_test.dart ports scenarios from the upstream SDK suites:
    • all seven signing algorithms
    • real ES256 callback signatures, in raw and DER form
    • BMFF signing and fragmented Merkle hashing
    • the embeddable error paths
    • cancellation mid-sign
    • HTTP resolver failures
    • key import, export, CSR and keystore signing
    • settings, reserve sizes and CAWG
    • concurrent signs
  • Fixtures: a third-party signed JPEG, an MP4 and key pairs for every algorithm, copied from the c2pa-android test resources.
  • The iOS integration step retries a run that stalls in Flutter's VM-service discovery on hosted simulators.

For reviewers

This is a breaking release (0.1.0). The CHANGELOG lists every change, including the C2paPlatform changes that matter only to code calling the platform interface directly.

@redaranj
redaranj added this pull request to stack #9 November 27, 2026 12:26
Base automatically changed from feat/library-updates to main November 30, 2026 10:32
Both SDKs (c2pa-rs 0.92) dropped global settings and now scope all
configuration to a context that can also carry a signer, progress,
cancellation and an HTTP resolver. The plugin is rebuilt around that
model.

Upstream features:
- C2paContext.create(settings, signer, onProgress, httpResolver) and
  cancel(), with native and Dart HTTP resolvers.
- ManifestBuilder signs with the context signer and adds signFile,
  setBasePath, ingredient archives and the data-hash/BMFF embeddable
  flow, plus C2pa.composeManifest.
- The reader adds crJSON, sidecar and remote manifests, fragment reading
  (Android) and SDK-provided MIME types.
- CawgIdentitySigner.
- iOS createCSR, importKey and enrollHardwareKey.
- readIngredientFromFile, ReaderOptions.dataDir and the hashed-signing
  calls are removed with the SDKs.

Dart API:
- Every failure is a sealed C2paException. Reading an asset without a
  manifest throws C2paManifestNotFoundException.
- Builder calls run in call order even when not awaited; the setters
  and every dispose() return futures. Finalizers release handles that
  are garbage collected undisposed.
- ValidationStatus gains trusted from validation_state.
- setValue takes JSON values and enrollHardwareKey returns a typed
  result.
- Stricter analyzer settings.

Native:
- A Pigeon 30.0.2 definition (pigeons/c2pa_api.dart) generates typed
  Dart, Kotlin and Swift bindings; CI checks that they are current.
- Each plugin runs SDK calls on one serial worker, so callbacks never
  block the UI and dispose never frees a builder under a running call.
- Fixes:
  - addIngredientFromFile now works.
  - Android truncates destinations and keeps action parameter types.
  - iOS applies Android's default created_assertion_labels.
  - createKey honours its algorithm.
  - iOS exports SubjectPublicKeyInfo public keys, tags keychain keys the
    way c2pa-swift reads them, and deletes keychain keys.
  - claimGenerator reads v2 claims.

Toolchain: Dart 3.13 / Flutter 3.47 (CI pins 3.47.9), Xcode 26.4+ for
c2pa-swift's Swift tools 6.3, Android compileSdk 36.

Tests:
- 307 unit tests, including a fake-host test of the Pigeon layer.
- Every integration test file now runs in CI on an iOS simulator and an
  Android emulator.
- A new parity suite ports the upstream SDK scenarios: all signing
  algorithms, real callback signatures, BMFF, embeddable error paths,
  cancellation, HTTP resolver failures, key management and concurrency.
@redaranj
redaranj force-pushed the feat/sync-with-c2pa-swift-android-0-1-x-apis branch from b55826f to e9c0f90 Compare November 30, 2026 10:32
@redaranj
redaranj merged commit 428e2b3 into main Nov 30, 2026
1 check passed
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.

1 participant