Skip to content

feat: adds a progress/cancel feature to Context for the c2pa-rs sdk#1927

Merged
gpeacock merged 16 commits intomainfrom
gpeacock/progress_cancel
Mar 24, 2026
Merged

feat: adds a progress/cancel feature to Context for the c2pa-rs sdk#1927
gpeacock merged 16 commits intomainfrom
gpeacock/progress_cancel

Conversation

@gpeacock
Copy link
Collaborator

@gpeacock gpeacock commented Mar 12, 2026

Progress/Cancel API

Adds a progress reporting and cancellation API to Context.

Attach a callback when building a context and receive structured notifications at each major phase of signing and reading operations.

Return false from the callback — or call context.cancel() from another thread — to abort with Error::OperationCancelled.
let context = Context::new().with_progress_callback(|phase, step, total| { println!("{phase:?} {step}/{total}"); true // return false to cancel });

The callback receives a ProgressPhase enum value, a 1-based step index, and a total step count (0 = indeterminate).

Phases emitted during a typical sign+verify cycle, in order:

VerifyingIngredient → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → Thumbnail → Hashing → Signing → Embedding → (verify after sign) → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → VerifyingIngredient

And during reading:

Reading → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → VerifyingIngredient

VerifyingIngredient reports accurate step/total counts; VerifyingSignature always reports 1/2 (COSE parse) then 2/2 (OCSP + full verify). VerifyingAssetHash fires immediately before the asset is re-hashed for integrity checking — the most time-consuming part of reading large files.

Includes c_ffi_api support

examples/progress.rs — demonstrates the API with elapsed timing output for both sign and read paths, allows cancel.

This API only applies to the context-based flows (Builder::from_shared_context, Reader::from_shared_context). Older convenience methods are unaffected.

gpeacock added 2 commits March 6, 2026 21:37
Progress API: Replace OperationPhase with ProgressPhase (#[repr(u8)]), and ProgressCallback trait with ProgressCallbackFunc (Fn(ProgressPhase, f32) -> bool). Progress is reported as f32 0.0–1.0 instead of u8 0–100.
Cancellation: Add cancel() and is_cancelled() on Context; remove Arc<AtomicBool> cancellation token. Add Error::OperationCancelled.
C FFI: Add c2pa_context_builder_set_progress_callback(builder, user_data, callback) and c2pa_context_cancel(ctx). Remove C2paCancellationToken and related APIs.
Coverage: Add check_progress in builder (save_to_stream), store, and claim so callbacks run during signing, embedding, and verification.
Tests: Add unit tests for progress/cancel in context.rs and integration tests in builder.rs.
Docs: Add docs/pro
Replaced f32 pct with (u32 step, u32 total) in the callback type
Renamed/replaced phases: Ingredients/Verification/RemoteFetch → Reading, VerifyingManifest, VerifyingSignature, VerifyingIngredient, VerifyingAssetHash, FetchingRemoteManifest (keeping Thumbnail, Hashing, Signing, Embedding)
added builder_sample.rs — Updated to demonstrate the new API with per-phase elapsed timing output and assertions against the new phase names
Added more instrumentation for phases.
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 12, 2026

Merging this PR will not alter performance

✅ 32 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing gpeacock/progress_cancel (897abee) with main (88c1273)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 86.30573% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.89%. Comparing base (88c1273) to head (897abee).

Files with missing lines Patch % Lines
sdk/src/claim.rs 76.19% 10 Missing ⚠️
sdk/src/assertions/data_hash.rs 81.81% 6 Missing ⚠️
sdk/src/crypto/ocsp/fetch.rs 0.00% 6 Missing ⚠️
c2pa_c_ffi/src/c_api.rs 76.19% 5 Missing ⚠️
sdk/src/assertions/bmff_hash.rs 79.16% 5 Missing ⚠️
sdk/src/utils/hash_utils.rs 81.81% 4 Missing ⚠️
sdk/src/assertions/box_hash.rs 95.08% 3 Missing ⚠️
sdk/src/builder.rs 91.66% 2 Missing ⚠️
sdk/src/store.rs 95.83% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1927      +/-   ##
==========================================
+ Coverage   76.87%   76.89%   +0.01%     
==========================================
  Files         175      175              
  Lines       42171    42438     +267     
==========================================
+ Hits        32418    32631     +213     
- Misses       9753     9807      +54     

☔ 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.

Copy link
Contributor

@tmathern tmathern left a comment

Choose a reason for hiding this comment

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

Is sdk/test_input a stray test file?

gpeacock added 10 commits March 16, 2026 16:30
Introduce hash_stream_by_alg_with_progress (pub(crate)) in hash_utils.rs; make hash_stream_by_alg a thin wrapper. Callbacks fire per HashRange.
Add _with_progress variants to DataHash, BmffHash, and BoxHash for both signing (gen_hash) and verification (verify_stream_hash); public functions become thin wrappers passing None.
Wire progress callbacks through builder.rs, store.rs, and claim.rs using context.check_progress(ProgressPhase::VerifyingAssetHash / Hashing, step, total).
Add FetchingOCSP and FetchingTimestamp phases to ProgressPhase; fire FetchingOCSP per OCSP responder in ocsp/fetch.rs.
This can work with any file and supports both reading (with one param, and signing/embedding.
remove changes to builder_sample<
remove test_input.jpg cruft
Co-authored-by: tmathern <60901087+tmathern@users.noreply.github.com>
@gpeacock gpeacock merged commit bbd3057 into main Mar 24, 2026
1 check passed
@gpeacock gpeacock deleted the gpeacock/progress_cancel branch March 24, 2026 20:18
@caiopensrc caiopensrc mentioned this pull request Mar 24, 2026
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