feat: adds a progress/cancel feature to Context for the c2pa-rs sdk#1927
Merged
feat: adds a progress/cancel feature to Context for the c2pa-rs sdk#1927
Conversation
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.
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
tmathern
reviewed
Mar 13, 2026
Contributor
tmathern
left a comment
There was a problem hiding this comment.
Is sdk/test_input a stray test file?
tmathern
reviewed
Mar 13, 2026
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
tmathern
approved these changes
Mar 24, 2026
Co-authored-by: tmathern <60901087+tmathern@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.