| // 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_CLAIM_MANIFEST_STORE_BUILDER_H_ | |
| #define THIRD_PARTY_CREDENTIO_CLAIM_MANIFEST_STORE_BUILDER_H_ | |
| #include <string> | |
| #include <vector> | |
| #include "absl/container/flat_hash_map.h" | |
| #include "absl/log/die_if_null.h" | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/string_view.h" | |
| #include "crypto/hash.h" | |
| #include "jumbf/box.h" | |
| #include "jumbf/box_builder.h" | |
| #include "proto/hashed_uri.pb.h" | |
| namespace credentio { | |
| // Struct holding the HashedUris for an ingredient's active manifest. | |
| struct IngredientManifestUris { | |
| HashedUri active_manifest; | |
| HashedUri claim_signature; | |
| }; | |
| // Builder for a manifest store. | |
| class ManifestStoreBuilder { | |
| public: | |
| explicit ManifestStoreBuilder(const HasherFactory* hasher_factory) | |
| : hasher_factory_(*ABSL_DIE_IF_NULL(hasher_factory)) {}; | |
| // Adds an ingredient manifest store via its serialized bytes. | |
| // Returns the HashedUris computed on the ingredient's active manifest. | |
| absl::StatusOr<IngredientManifestUris> AddIngredientManifestStore( | |
| absl::string_view manifest_store_bytes); | |
| // Finish writing the manifest store. This consumes the builder, use | |
| // `std::move(builder).Finalize()`; | |
| absl::StatusOr<jumbf::BuiltSuperBox> Finalize( | |
| jumbf::BuiltSuperBox&& active_manifest) &&; | |
| private: | |
| struct ManifestInfo { | |
| bool copied_to_manifest_store = false; // Already copied by Finalize? | |
| }; | |
| absl::flat_hash_map<std::string, ManifestInfo> manifest_info_; | |
| // Factory for creating hashers. Used to compute HashedUris. | |
| const HasherFactory& hasher_factory_; | |
| // Ingredient manifests added to the manifest store. | |
| std::vector<jumbf::SuperBox> ingredient_manifest_stores_; | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_CLAIM_MANIFEST_STORE_BUILDER_H_ |