blob: 4a88fa258543bb3aa993fe5b54dd61b9394e986a [file]
// 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.
//
#include "validator/validation_result_internal.h"
#include <memory>
#include "absl/algorithm/container.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "proto/manifest.pb.h"
#include "proto/validation_result.pb.h"
#include "proto/validation_status.pb.h"
namespace credentio {
absl::StatusOr<std::unique_ptr<ValidationResultProto>> MakeFullValidationResult(
std::unique_ptr<PartialValidationResultProto> partial_result) {
if (partial_result->active_manifest().validation().failures().empty()) {
if (!absl::c_any_of(
partial_result->active_manifest().validation().successes(),
[&](ValidationStatus status) {
if (status.code() == "com.google.assertion.dataHash.match" ||
status.code() == "com.google.assertion.bmffHash.match" ||
status.code() == "com.google.assertion.boxesHash.match" ||
status.code() ==
"com.google.assertion.collectionHash.match" ||
status.code() == "assertion.dataHash.match" ||
status.code() == "assertion.bmffHash.match" ||
status.code() == "assertion.boxesHash.match" ||
status.code() == "assertion.collectionHash.match") {
return true;
}
return false;
})) {
return absl::InternalError(
"No failures encountered during validation but no hard binding "
"assertion match was recorded either.");
}
}
auto result = std::make_unique<ValidationResultProto>();
result->mutable_active_manifest()->Swap(
partial_result->mutable_active_manifest());
result->mutable_ingredient_manifests()->Swap(
partial_result->mutable_ingredient_manifests());
if (partial_result->has_spec_version()) {
result->set_spec_version(partial_result->spec_version());
}
if (partial_result->has_trust_list_uri()) {
result->set_trust_list_uri(partial_result->trust_list_uri());
}
return result;
}
} // namespace credentio