blob: e70c5ca2a42a7ad07d5f1fd2aea61e546683c240 [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 "assertion/assertion_referencer.h"
#include <memory>
#include <optional>
#include "absl/status/status.h"
#include "absl/status/status_macros.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "crypto/hash.h"
#include "jumbf/box_builder.h"
#include "jumbf/utils.h"
#include "proto/assertion.pb.h"
#include "proto/hashed_uri.pb.h"
namespace credentio {
absl::StatusOr<HashedUri> AssertionReferencer::Generate(
const jumbf::BuiltSuperBox& assertion_box) const {
if (!assertion_box.description_label().has_value()) {
return absl::InvalidArgumentError(
"the assertion box must have a description label");
}
HashedUri uri;
uri.set_url(absl::StrCat("self#jumbf=c2pa.assertions/",
*assertion_box.description_label()));
absl::Cord serialized_assertion = assertion_box.Peek();
absl::string_view serialized_assertion_view = serialized_assertion.Flatten();
ABSL_ASSIGN_OR_RETURN(auto hasher, hasher_factory_.Create());
ABSL_ASSIGN_OR_RETURN(auto content,
jumbf::StripBoxHeaders(serialized_assertion_view));
hasher->Update(content);
uri.set_hash(hasher->Digest());
return uri;
}
} // namespace credentio