// services/network/public/mojom/ssl_info.mojom-shared.h 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.

#ifndef SERVICES_NETWORK_PUBLIC_MOJOM_SSL_INFO_MOJOM_SHARED_H_
#define SERVICES_NETWORK_PUBLIC_MOJOM_SSL_INFO_MOJOM_SHARED_H_

#include <stdint.h>

#include <functional>
#include <iosfwd>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/array_data_view.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/system/message_pipe.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "services/network/public/mojom/ssl_info.mojom-shared-internal.h"
#include "services/network/public/mojom/ct_policy_status.mojom-shared.h"
#include "services/network/public/mojom/hash_value.mojom-shared.h"
#include "services/network/public/mojom/signed_certificate_timestamp_and_status.mojom-shared.h"
#include "services/network/public/mojom/x509_certificate.mojom-shared.h"




#include "services/network/public/mojom/ssl_info.mojom-data-view.h"  // IWYU pragma: export




namespace std {

template <>
struct hash<::network::mojom::SSLInfoHandshakeType>
    : public mojo::internal::EnumHashImpl<::network::mojom::SSLInfoHandshakeType> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::network::mojom::SSLInfoHandshakeType, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::network::mojom::SSLInfoHandshakeType, UserType>;

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    auto known_value = ::mojo::internal::ToKnownEnumValueHelper(
        static_cast<::network::mojom::SSLInfoHandshakeType>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::network::mojom::SSLInfoHandshakeType, UserType> ||
                        HasInfallibleConversion(::network::mojom::SSLInfoHandshakeType()),
                    "::network::mojom::SSLInfoHandshakeType does not have an infallible conversion, "
                    "use an optional return type.");
      *output = Traits::FromMojom(known_value);
      return true;
    } else {
      static_assert(
          requires {
            {
              Traits::FromMojom(known_value)
            } -> std::same_as<std::optional<UserType>>;
          }, "FromMojom must return by value or optional.");
      std::optional<UserType> from_mojom = Traits::FromMojom(known_value);
      if (from_mojom) {
        *output = *from_mojom;
      }
      return from_mojom.has_value();
    }
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::network::mojom::SSLInfoDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::network::mojom::SSLInfoDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::network::mojom::internal::SSLInfo_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();

    decltype(Traits::cert(input)) in_cert = Traits::cert(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->cert)::BaseType> cert_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::network::mojom::X509CertificateDataView>(
      in_cert,
      cert_fragment);

    fragment->cert.Set(
        cert_fragment.is_null() ? nullptr : cert_fragment.data());

    decltype(Traits::unverified_cert(input)) in_unverified_cert = Traits::unverified_cert(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->unverified_cert)::BaseType> unverified_cert_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::network::mojom::X509CertificateDataView>(
      in_unverified_cert,
      unverified_cert_fragment);

    fragment->unverified_cert.Set(
        unverified_cert_fragment.is_null() ? nullptr : unverified_cert_fragment.data());

    fragment->cert_status = Traits::cert_status(input);

    fragment->key_exchange_group = Traits::key_exchange_group(input);

    fragment->peer_signature_algorithm = Traits::peer_signature_algorithm(input);

    fragment->connection_status = Traits::connection_status(input);

    fragment->is_issued_by_known_root = Traits::is_issued_by_known_root(input);

    fragment->pkp_bypassed = Traits::pkp_bypassed(input);

    fragment->client_cert_sent = Traits::client_cert_sent(input);

    fragment->encrypted_client_hello = Traits::encrypted_client_hello(input);

    
    mojo::internal::Serialize<::network::mojom::SSLInfoHandshakeType>(
      Traits::handshake_type(input),
      &fragment->handshake_type);

    decltype(Traits::public_key_hashes(input)) in_public_key_hashes = Traits::public_key_hashes(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->public_key_hashes)::BaseType>
        public_key_hashes_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& public_key_hashes_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<::network::mojom::SHA256HashValueDataView>>(
      in_public_key_hashes,
      public_key_hashes_fragment,
      &public_key_hashes_validate_params);

    fragment->public_key_hashes.Set(
        public_key_hashes_fragment.is_null() ? nullptr : public_key_hashes_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->public_key_hashes.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null public_key_hashes in SSLInfo struct");

    decltype(Traits::signed_certificate_timestamps(input)) in_signed_certificate_timestamps = Traits::signed_certificate_timestamps(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->signed_certificate_timestamps)::BaseType>
        signed_certificate_timestamps_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& signed_certificate_timestamps_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<::network::mojom::SignedCertificateTimestampAndStatusDataView>>(
      in_signed_certificate_timestamps,
      signed_certificate_timestamps_fragment,
      &signed_certificate_timestamps_validate_params);

    fragment->signed_certificate_timestamps.Set(
        signed_certificate_timestamps_fragment.is_null() ? nullptr : signed_certificate_timestamps_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->signed_certificate_timestamps.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null signed_certificate_timestamps in SSLInfo struct");

    
    mojo::internal::Serialize<::network::mojom::CTPolicyCompliance>(
      Traits::ct_policy_compliance(input),
      &fragment->ct_policy_compliance);

    fragment->is_fatal_cert_error = Traits::is_fatal_cert_error(input);
  }

  static bool Deserialize(::network::mojom::internal::SSLInfo_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::network::mojom::SSLInfoDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal

}  // namespace mojo


namespace network::mojom {

inline void SSLInfoDataView::GetCertDataView(
    ::network::mojom::X509CertificateDataView* output) {
  auto pointer = data_->cert.Get();
  *output = ::network::mojom::X509CertificateDataView(pointer, message_);
}
inline void SSLInfoDataView::GetUnverifiedCertDataView(
    ::network::mojom::X509CertificateDataView* output) {
  auto pointer = data_->unverified_cert.Get();
  *output = ::network::mojom::X509CertificateDataView(pointer, message_);
}
inline void SSLInfoDataView::GetPublicKeyHashesDataView(
    mojo::ArrayDataView<::network::mojom::SHA256HashValueDataView>* output) {
  auto pointer = data_->public_key_hashes.Get();
  *output = mojo::ArrayDataView<::network::mojom::SHA256HashValueDataView>(pointer, message_);
}
inline void SSLInfoDataView::GetSignedCertificateTimestampsDataView(
    mojo::ArrayDataView<::network::mojom::SignedCertificateTimestampAndStatusDataView>* output) {
  auto pointer = data_->signed_certificate_timestamps.Get();
  *output = mojo::ArrayDataView<::network::mojom::SignedCertificateTimestampAndStatusDataView>(pointer, message_);
}



}  // network::mojom

// Declare TraceFormatTraits for enums, which should be defined in ::perfetto
// namespace.

namespace perfetto {

template <>
struct  TraceFormatTraits<::network::mojom::SSLInfoHandshakeType> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::network::mojom::SSLInfoHandshakeType value);
};

} // namespace perfetto

#endif  // SERVICES_NETWORK_PUBLIC_MOJOM_SSL_INFO_MOJOM_SHARED_H_