blob: 158c2e6c684ff4b53d2f66855a9b3c461c5f4a9e [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_CLAIM_SIGNER_H_
#define THIRD_PARTY_CREDENTIO_CLAIM_SIGNER_H_
#include <optional>
#include <string>
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "async/async_context.h"
namespace credentio {
enum class TimeStampingMode {
kOptional,
kRequired,
kOmittedWithPadding,
};
// Interface for a signer to sign a Claim according to
// https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html#_signing_a_claim.
class ClaimSigner {
public:
virtual ~ClaimSigner() = default;
struct Options {
TimeStampingMode time_stamping_mode = TimeStampingMode::kOptional;
AsyncContext async_context = AsyncContext();
};
struct SignResult {
// Serialized COSE_Sign1_Tagged structure.
std::string signature;
};
// Signs the serialized CBOR of the claim and returns the serialized
// COSE_Sign1_Tagged structure that will be written into the C2PA Claim
// Signature box. For more details, see
// https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html#_signing_a_claim.
// It guarantees that the size of the result is fixed and is a function of
// `max_signature_bytes_size()` and `max_timestamp_byte_size()` of the
// CryptoWriteHandler rather than of the actual signature and timestamp sizes.
virtual void Sign(
absl::string_view claim, Options options,
absl::AnyInvocable<void(absl::StatusOr<SignResult>) &&> cb) const = 0;
};
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_CLAIM_SIGNER_H_