| // 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_TESTING_JUMBF_UTILS_H_ |
| #define THIRD_PARTY_CREDENTIO_TESTING_JUMBF_UTILS_H_ |
| |
| #include <cstdint> |
| #include <optional> |
| #include <string> |
| |
| #include "absl/strings/string_view.h" |
| #include "absl/types/span.h" |
| #include "assertion/assertion_encoder.h" |
| #include "jumbf/box.h" |
| #include "proto/assertion.pb.h" |
| |
| namespace credentio { |
| |
| // Parses the given bytes as a JUMBF superbox. The underlying bytes must outlive |
| // the returned SuperBox. |
| jumbf::SuperBox ParseSuperBoxOrDie(const std::string* bytes); |
| |
| // NOTE: Helpers below returning jumbf::SuperBox set `raw_bytes` to a fixed |
| // test value. |
| |
| jumbf::SuperBox CreateManifestStore( |
| absl::Span<const jumbf::SuperBox> manifests); |
| jumbf::SuperBox CreateStandardManifest(absl::string_view label, |
| absl::Span<const jumbf::SuperBox> boxes); |
| jumbf::SuperBox CreateUpdateManifest(absl::string_view label, |
| absl::Span<const jumbf::SuperBox> boxes); |
| jumbf::SuperBox CreateAssertionStoreBox(); |
| jumbf::SuperBox CreateAssertionStoreBox( |
| absl::Span<const jumbf::SuperBox> assertions); |
| jumbf::SuperBox CreateAssertionBoxFromCbor(absl::string_view label, |
| absl::string_view cbor); |
| jumbf::SuperBox CreateAssertionBoxFromEmbeddedFile( |
| absl::string_view label, absl::string_view media_type, |
| absl::string_view file_contents, |
| std::optional<absl::string_view> file_name = std::nullopt); |
| jumbf::SuperBox CreateActionsAssertionBoxFromCbor(absl::string_view cbor); |
| jumbf::SuperBox CreateBmffBasedHashAssertionBoxFromCbor(absl::string_view cbor); |
| jumbf::SuperBox CreateDataHashAssertionBoxFromCbor(absl::string_view cbor); |
| jumbf::SuperBox CreateAssertionBoxFromJson(absl::string_view label, |
| absl::string_view json); |
| |
| // Returns a serialized claim signature JUMBF box. |
| std::string EncodeClaimSignatureBox(absl::string_view cbor); |
| |
| // Returns a serialized assertion JUMBF box. |
| std::string EncodeAssertionBoxOrDie(const Assertion& assertion, |
| const AssertionEncoder& encoder); |
| |
| // Returns the hash of the given box per |
| // https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html#_hashed_uris. |
| std::string GetHash(absl::string_view algorithm, const jumbf::SuperBox& box); |
| |
| // This creates the start of a manifest store payload, just enough to pass |
| // MightBeC2paManifestStore(...). |
| std::string CreateStartOfManifestStorePayload( |
| absl::Span<const uint8_t> prefix = {}); |
| |
| } // namespace credentio |
| |
| #endif // THIRD_PARTY_CREDENTIO_TESTING_JUMBF_UTILS_H_ |