| // 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_UTILS_DUAL_STATUS_TRACKER_H_ | |
| #define THIRD_PARTY_CREDENTIO_UTILS_DUAL_STATUS_TRACKER_H_ | |
| #include <memory> | |
| #include <utility> | |
| #include "absl/base/nullability.h" | |
| #include "absl/status/statusor.h" | |
| #include "constants/status_codes.h" | |
| #include "proto/manifest.pb.h" | |
| #include "proto/validation_result.pb.h" | |
| #include "proto/validation_status.pb.h" | |
| #include "utils/status_tracker.h" | |
| #include "validator/tracker.h" | |
| namespace credentio { | |
| // A tracker for writing hard binding success and failure codes to the manifest | |
| // containing the hard binding assertion and optionally the active manifest. | |
| // | |
| // The success and failure codes are written to the manifest containing the | |
| // assertion using the provided ValidationTracker and, if the manifest | |
| // containing the assertion is not the active manifest, optionally to the active | |
| // manifest using the optional ValidationTracker. | |
| // | |
| // The success and failure codes are written to the active manifest using a | |
| // google-code prefixed version of the c2pa success/failure code. This is | |
| // necessary because the summarizer only reads from the active manifest and | |
| // needs the success/failure codes to know which hard binding assertions were | |
| // evaluated. | |
| class DualStatusTracker : public StatusTracker { | |
| public: | |
| static absl::StatusOr<std::unique_ptr<DualStatusTracker>> | |
| FromPartialValidationResult( | |
| PartialValidationResultProto* absl_nonnull partial_validation_result); | |
| void RecordSuccess(SuccessStatusCode code, | |
| ValidationTracker::RecordOptions options) override; | |
| void RecordFailure(FailureStatusCode code, | |
| ValidationTracker::RecordOptions options) override; | |
| void RecordInformational(InformationalStatusCode code, | |
| ValidationTracker::RecordOptions options) override; | |
| bool WritesToIngredientManifest() const { return active_tracker_ != nullptr; } | |
| private: | |
| // The tracker for the manifest containing the hard binding assertion. | |
| std::unique_ptr<ValidationTracker> assertion_tracker_; | |
| // The tracker for the active manifest if the assertion is not in the active | |
| // manifest. | |
| std::unique_ptr<ValidationTracker> active_tracker_; | |
| explicit DualStatusTracker(Manifest* absl_nonnull assertion_manifest, | |
| Manifest* absl_nullable active_manifest) | |
| : assertion_tracker_( | |
| std::make_unique<ValidationTracker>(assertion_manifest)), | |
| active_tracker_( | |
| active_manifest == nullptr | |
| ? nullptr | |
| : std::make_unique<ValidationTracker>(active_manifest)) {}; | |
| // This constructor should only be used by the static factory methods. | |
| explicit DualStatusTracker( | |
| std::unique_ptr<ValidationTracker> absl_nonnull assertion_tracker, | |
| std::unique_ptr<ValidationTracker> absl_nullable active_tracker = nullptr) | |
| : assertion_tracker_(std::move(assertion_tracker)), | |
| active_tracker_(std::move(active_tracker)) {}; | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_UTILS_DUAL_STATUS_TRACKER_H_ |