| // 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_VALIDATOR_ASSET_VALIDATOR_H_ | |
| #define THIRD_PARTY_CREDENTIO_VALIDATOR_ASSET_VALIDATOR_H_ | |
| #include <memory> | |
| #include <optional> | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/string_view.h" | |
| #include "riegeli/bytes/reader.h" | |
| #include "validator/result.h" | |
| namespace credentio { | |
| // A validator of C2PA metadata embedded in media files (assets). | |
| class AssetValidator { | |
| public: | |
| virtual ~AssetValidator() = default; | |
| // Extracts and verifies content credentials from an asset of a supported | |
| // type. Returns an error if validation could not be performed (e.g., due to | |
| // internal error) or no C2PA metadata is present. | |
| // | |
| // The `input` is a riegeli::Reader over the asset. It must support backwards | |
| // seeks (e.g., riegeli::FileReader, riegeli::StringReader). | |
| // The `media_type` is the IANA media type of the asset (e.g. "image/jpeg"). | |
| // If not provided, the media type will be determined from the input. | |
| // | |
| // Example: | |
| // File input: | |
| // ABSL_ASSIGN_OR_RETURN(std::string media_type, | |
| // credentio::MediaType(file_path)); | |
| // riegeli::FileReader reader(file_path); | |
| // ABSL_RETURN_IF_ERROR(reader.status()); | |
| // absl::StatusOr<std::unique_ptr<ValidationResult>> result = | |
| // validator->Validate(reader, *media_type); | |
| // | |
| // String input: | |
| // std::string contents = "contents"; | |
| // riegeli::StringReader reader(contents); | |
| // absl::StatusOr<std::unique_ptr<ValidationResult>> result = | |
| // validator->Validate(reader, "image/jpeg"); | |
| virtual absl::StatusOr<std::unique_ptr<ValidationResult>> Validate( | |
| riegeli::Reader& input, | |
| std::optional<absl::string_view> media_type) const = 0; | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_VALIDATOR_ASSET_VALIDATOR_H_ |