@@ -1022,6 +1022,59 @@ namespace c2pa
10221022 // / @return A formatted copy of the data.
10231023 static std::vector<unsigned char > format_embeddable (const std::string &format, std::vector<unsigned char > &data);
10241024
1025+ // / @brief Check if the given format requires a placeholder embedding step.
1026+ // / @details Returns false for BoxHash-capable formats when prefer_box_hash is enabled in
1027+ // / the context settings (no placeholder needed — hash covers the full asset).
1028+ // / Always returns true for BMFF formats (MP4, etc.) regardless of settings.
1029+ // / @param format The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4").
1030+ // / @return true if placeholder() must be called and embedded before sign_embeddable(); false otherwise.
1031+ // / @throws C2paException on error.
1032+ bool needs_placeholder (const std::string &format);
1033+
1034+ // / @brief Create a composed placeholder manifest to embed in the asset.
1035+ // / @details The signer (and its reserve size) are obtained from the Builder's Context.
1036+ // / For BMFF assets, if core.merkle_tree_chunk_size_in_kb is set in the context
1037+ // / settings, the placeholder will include pre-allocated Merkle map slots.
1038+ // / Returns empty bytes for formats that do not need a placeholder (BoxHash).
1039+ // / The placeholder size is stored internally so sign_embeddable() returns bytes
1040+ // / of exactly the same size, enabling in-place patching.
1041+ // / @param format The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4").
1042+ // / @return Composed placeholder bytes ready to embed into the asset.
1043+ // / @throws C2paException on error.
1044+ std::vector<unsigned char > placeholder (const std::string &format);
1045+
1046+ // / @brief Register the byte ranges where the placeholder was embedded (DataHash workflow).
1047+ // / @details Call this after embedding the placeholder bytes into the asset and before
1048+ // / update_hash_from_stream(). The exclusions replace the dummy ranges set by
1049+ // / placeholder() so the asset hash covers all bytes except the manifest slot.
1050+ // / Exclusions are (start, length) pairs in asset byte coordinates.
1051+ // / @param exclusions Vector of (start, length) pairs describing the embedded placeholder region.
1052+ // / @throws C2paException if no DataHash assertion exists or on other error.
1053+ void set_data_hash_exclusions (const std::vector<std::pair<uint64_t , uint64_t >> &exclusions);
1054+
1055+ // / @brief Compute and store the asset hash by reading a stream.
1056+ // / @details Automatically detects the hard binding type from the builder state:
1057+ // / - DataHash: uses exclusion ranges already registered via set_data_hash_exclusions().
1058+ // / - BmffHash: uses path-based exclusions from the BMFF assertion (UUID box, mdat).
1059+ // / - BoxHash: hashes each format-specific box individually.
1060+ // / Call set_data_hash_exclusions() before this for DataHash workflows.
1061+ // / @param format The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4").
1062+ // / @param stream The asset stream to hash. Must include the embedded placeholder bytes.
1063+ // / @throws C2paException on error.
1064+ void update_hash_from_stream (const std::string &format, std::istream &stream);
1065+
1066+ // / @brief Sign and return the final manifest bytes, ready for embedding.
1067+ // / @details Operates in two modes:
1068+ // / - Placeholder mode (after placeholder()): zero-pads the signed manifest to the
1069+ // / pre-committed placeholder size, enabling in-place patching of the asset.
1070+ // / - Direct mode (no placeholder): returns the actual signed manifest size.
1071+ // / Requires a valid hard binding assertion (set via update_hash_from_stream()).
1072+ // / The signer is obtained from the Builder's Context.
1073+ // / @param format The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4").
1074+ // / @return Signed manifest bytes ready to embed into the asset.
1075+ // / @throws C2paException on error.
1076+ std::vector<unsigned char > sign_embeddable (const std::string &format);
1077+
10251078 // / @brief Get a list of mime types that the Builder supports.
10261079 // / @return Vector of supported MIME type strings.
10271080 static std::vector<std::string> supported_mime_types ();
0 commit comments