// services/network/public/mojom/signed_certificate_timestamp.mojom-shared.cc is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/public/mojom/signed_certificate_timestamp.mojom-shared.h"
#include <ostream>
#include <utility>
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "services/network/public/mojom/signed_certificate_timestamp.mojom-params-data.h"
namespace network {
namespace mojom {

NOINLINE static const char* HashAlgorithmToStringHelper(HashAlgorithm value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case HashAlgorithm::HASH_ALGO_NONE:
      return "HASH_ALGO_NONE";
    case HashAlgorithm::HASH_ALGO_MD5:
      return "HASH_ALGO_MD5";
    case HashAlgorithm::HASH_ALGO_SHA1:
      return "HASH_ALGO_SHA1";
    case HashAlgorithm::HASH_ALGO_SHA224:
      return "HASH_ALGO_SHA224";
    case HashAlgorithm::HASH_ALGO_SHA256:
      return "HASH_ALGO_SHA256";
    case HashAlgorithm::HASH_ALGO_SHA384:
      return "HASH_ALGO_SHA384";
    case HashAlgorithm::HASH_ALGO_SHA512:
      return "HASH_ALGO_SHA512";
    default:
      return nullptr;
  }
}

std::string HashAlgorithmToString(HashAlgorithm value) {
  const char *str = HashAlgorithmToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown HashAlgorithm value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, HashAlgorithm value) {
  return os << HashAlgorithmToString(value);
}

NOINLINE static const char* SignatureAlgorithmToStringHelper(SignatureAlgorithm value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SignatureAlgorithm::SIG_ALGO_ANONYMOUS:
      return "SIG_ALGO_ANONYMOUS";
    case SignatureAlgorithm::SIG_ALGO_RSA:
      return "SIG_ALGO_RSA";
    case SignatureAlgorithm::SIG_ALGO_DSA:
      return "SIG_ALGO_DSA";
    case SignatureAlgorithm::SIG_ALGO_ECDSA:
      return "SIG_ALGO_ECDSA";
    default:
      return nullptr;
  }
}

std::string SignatureAlgorithmToString(SignatureAlgorithm value) {
  const char *str = SignatureAlgorithmToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SignatureAlgorithm value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SignatureAlgorithm value) {
  return os << SignatureAlgorithmToString(value);
}

NOINLINE static const char* SCTVersionToStringHelper(SCTVersion value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SCTVersion::kV1:
      return "kV1";
    default:
      return nullptr;
  }
}

std::string SCTVersionToString(SCTVersion value) {
  const char *str = SCTVersionToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SCTVersion value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SCTVersion value) {
  return os << SCTVersionToString(value);
}

NOINLINE static const char* SCTOriginToStringHelper(SCTOrigin value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SCTOrigin::kEmbedded:
      return "kEmbedded";
    case SCTOrigin::kFromTlsExtension:
      return "kFromTlsExtension";
    case SCTOrigin::kFromOcspResponse:
      return "kFromOcspResponse";
    default:
      return nullptr;
  }
}

std::string SCTOriginToString(SCTOrigin value) {
  const char *str = SCTOriginToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SCTOrigin value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SCTOrigin value) {
  return os << SCTOriginToString(value);
}

namespace internal {


// static
bool DigitallySigned_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const DigitallySigned_Data* object =
      static_cast<const DigitallySigned_Data*>(data);


  if (!::network::mojom::internal::HashAlgorithm_Data
        ::Validate(object->hash_algorithm, validation_context))
    return false;


  if (!::network::mojom::internal::SignatureAlgorithm_Data
        ::Validate(object->signature_algorithm, validation_context))
    return false;

  if (!mojo::internal::ValidatePointerNonNullable(
          object->signature, 3, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& signature_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->signature, validation_context,
                                         &signature_validate_params)) {
    return false;
  }

  return true;
}

DigitallySigned_Data::DigitallySigned_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SignedCertificateTimestamp_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 56, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SignedCertificateTimestamp_Data* object =
      static_cast<const SignedCertificateTimestamp_Data*>(data);


  if (!::network::mojom::internal::SCTVersion_Data
        ::Validate(object->version, validation_context))
    return false;

  if (!mojo::internal::ValidatePointerNonNullable(
          object->log_id, 2, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& log_id_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->log_id, validation_context,
                                         &log_id_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->timestamp, 3, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateStruct(object->timestamp, validation_context))
    return false;

  if (!mojo::internal::ValidatePointerNonNullable(
          object->extensions, 4, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& extensions_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->extensions, validation_context,
                                         &extensions_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->signature, 5, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateStruct(object->signature, validation_context))
    return false;


  if (!::network::mojom::internal::SCTOrigin_Data
        ::Validate(object->origin, validation_context))
    return false;

  if (!mojo::internal::ValidatePointerNonNullable(
          object->log_description, 7, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& log_description_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->log_description, validation_context,
                                         &log_description_validate_params)) {
    return false;
  }

  return true;
}

SignedCertificateTimestamp_Data::SignedCertificateTimestamp_Data()
    : header_({sizeof(*this), 0}) {}

}  // namespace internal
}  // namespace mojom
}  // namespace network

namespace perfetto {

// static
void TraceFormatTraits<::network::mojom::HashAlgorithm>::WriteIntoTrace(
   perfetto::TracedValue context, ::network::mojom::HashAlgorithm value) {
  return std::move(context).WriteString(::network::mojom::HashAlgorithmToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::network::mojom::SignatureAlgorithm>::WriteIntoTrace(
   perfetto::TracedValue context, ::network::mojom::SignatureAlgorithm value) {
  return std::move(context).WriteString(::network::mojom::SignatureAlgorithmToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::network::mojom::SCTVersion>::WriteIntoTrace(
   perfetto::TracedValue context, ::network::mojom::SCTVersion value) {
  return std::move(context).WriteString(::network::mojom::SCTVersionToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::network::mojom::SCTOrigin>::WriteIntoTrace(
   perfetto::TracedValue context, ::network::mojom::SCTOrigin value) {
  return std::move(context).WriteString(::network::mojom::SCTOriginToString(value));
}

} // namespace perfetto