| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_FORMATS_BMFF_EMBEDDER_H_ | |
| #define THIRD_PARTY_CREDENTIO_FORMATS_BMFF_EMBEDDER_H_ | |
| #include <cstdint> | |
| #include <vector> | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/string_view.h" | |
| #include "formats/byte_range.h" | |
| #include "proto/bmff_based_hash_assertion.pb.h" | |
| #include "riegeli/bytes/reader.h" | |
| #include "riegeli/bytes/writer.h" | |
| #include "utils/byte_instruction.h" | |
| namespace credentio { | |
| // Embedder for inserting a C2PA manifest store into a BMFF file. | |
| class BmffEmbedder { | |
| public: | |
| // Reads through the source, locating where the manifest should be inserted | |
| // and where any atoms needing offset adjustment are located. Simultaneously | |
| // computes the hard binding hash of the asset. | |
| absl::StatusOr<std::vector<ByteInstruction>> InspectAndHash( | |
| riegeli::Reader& source, uint64_t manifest_store_size, | |
| const ByteRange& insertion_point, bool can_replace_manifest, | |
| BmffBasedHashAssertion& assertion) const; | |
| }; | |
| // Calculates the size of the C2PA (UUID) box in the BMFF format. | |
| int64_t CalculateC2paSizeBmff(uint64_t manifest_store_size); | |
| // Writes the C2PA manifest store to the output in the BMFF format at the | |
| // current position and returns the offset of the appended box. | |
| // | |
| // NOTE: This shall be called before the first 'mdat' box in the file and | |
| // before any 'moov' box in the file. To accommodate major_brand and | |
| // compatible_brand verification, it shall be called after the 'ftyp' box. | |
| // | |
| // BMFF files with Merkle tree content bindings are not supported. | |
| absl::Status WriteC2paBmff(absl::string_view manifest_store, | |
| riegeli::Writer& output); | |
| // Creates a free box in the BMFF format at the current position. | |
| absl::Status CreateFreeBox(uint64_t size, riegeli::Writer& output); | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_BMFF_EMBEDDER_H_ |