blob: 8ffedc49570175fa5f9c83e921024ef389ee087f [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.
//
#ifndef THIRD_PARTY_CREDENTIO_ASSERTION_ASSERTION_PARSER_H_
#define THIRD_PARTY_CREDENTIO_ASSERTION_ASSERTION_PARSER_H_
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
#include "proto/assertion.pb.h"
#include "validator/tracker.h"
namespace credentio {
// Returns the label with any multiple instance suffix (e.g., `__1`) removed.
absl::string_view StripMultipleInstanceSuffix(absl::string_view label);
// A helper class to match an assertion type (e.g., c2pa.actions.v2).
class AssertionTypeMatcher {
public:
explicit AssertionTypeMatcher(absl::string_view label) : label_(label) {}
bool Matches(absl::string_view label) const;
private:
const std::string label_;
};
class AssertionParser {
public:
AssertionParser() = default;
// Parses the given assertion content into an Assertion proto.
std::optional<Assertion> ParseCbor(
absl::string_view label, absl::string_view content,
ValidationTracker& validation_tracker) const;
// Parses the given thumbnail assertion into an Assertion proto.
std::optional<Assertion> ParseThumbnail(
absl::string_view label, absl::string_view media_type,
absl::string_view data, std::optional<absl::string_view> file_name,
ValidationTracker& validation_tracker) const;
std::optional<Assertion> ParseMetadata(
absl::string_view label, absl::string_view content,
ValidationTracker& validation_tracker) const;
};
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_ASSERTION_ASSERTION_PARSER_H_