| // 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_COSE_VALIDATION_STATUS_UTIL_H_ | |
| #define THIRD_PARTY_CREDENTIO_COSE_VALIDATION_STATUS_UTIL_H_ | |
| #include <type_traits> | |
| #include "absl/strings/str_cat.h" | |
| #include "absl/strings/string_view.h" | |
| #include "constants/status_codes.h" | |
| #include "proto/validation_status.pb.h" | |
| namespace credentio { | |
| struct RecordOptions { | |
| absl::string_view url = ""; | |
| absl::string_view explanation = ""; | |
| }; | |
| template <typename StatusCode> | |
| void RecordStatus(ValidationStatusSet* status_set, StatusCode code, | |
| RecordOptions options = {}) { | |
| ValidationStatus* status = nullptr; | |
| if constexpr (std::is_same_v<StatusCode, SuccessStatusCode>) { | |
| status = status_set->add_successes(); | |
| } else if constexpr (std::is_same_v<StatusCode, InformationalStatusCode>) { | |
| status = status_set->add_informationals(); | |
| } else if constexpr (std::is_same_v<StatusCode, FailureStatusCode>) { | |
| status = status_set->add_failures(); | |
| } | |
| status->set_code(absl::StrCat(code)); | |
| if (!options.url.empty()) { | |
| status->set_url(options.url); | |
| } | |
| if (!options.explanation.empty()) { | |
| status->set_explanation(options.explanation); | |
| } | |
| } | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_COSE_VALIDATION_STATUS_UTIL_H_ |