// components/private_ai/mojom/oak_session.mojom.h is auto generated by mojom_bindings_generator.py, do not edit

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

#ifndef COMPONENTS_PRIVATE_AI_MOJOM_OAK_SESSION_MOJOM_H_
#define COMPONENTS_PRIVATE_AI_MOJOM_OAK_SESSION_MOJOM_H_

#include <stdint.h>

#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"

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

#include "components/private_ai/mojom/oak_session.mojom-features.h"  // IWYU pragma: export
#include "components/private_ai/mojom/oak_session.mojom-shared.h"  // IWYU pragma: export
#include "components/private_ai/mojom/oak_session.mojom-forward.h"  // IWYU pragma: export
#include "sandbox/policy/mojom/sandbox.mojom-forward.h"
#include <string>
#include <vector>

#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"


#include "components/private_ai/mojom/oak_session_mojom_traits.h"




namespace private_ai::mojom {

class OakSessionProxy;

template <typename ImplRefTraits>
class OakSessionStub;

class OakSessionRequestValidator;
class OakSessionResponseValidator;


class OakSession
    : public OakSessionInterfaceBase {
 public:
  using IPCStableHashFunction = uint32_t(*)();
  static constexpr const char* Name_ = "private_ai.mojom.OakSession";
  static IPCStableHashFunction MessageToMethodInfo_(mojo::Message& message);
  static const char* MessageToMethodName_(mojo::Message& message);
  static constexpr auto kServiceSandbox = sandbox::mojom::Sandbox::kService;
  static constexpr uint32_t Version_ = 0;
  static constexpr bool PassesAssociatedKinds_ = false;
  static constexpr bool HasUninterruptableMethods_ = false;

  using Base_ = OakSessionInterfaceBase;
  using Proxy_ = OakSessionProxy;

  template <typename ImplRefTraits>
  using Stub_ = OakSessionStub<ImplRefTraits>;

  using RequestValidator_ = OakSessionRequestValidator;
  using ResponseValidator_ = OakSessionResponseValidator;
  enum MethodMinVersions : uint32_t {
    kInitiateHandshakeMinVersion = 0,
    kCompleteHandshakeMinVersion = 0,
    kEncryptMinVersion = 0,
    kDecryptMinVersion = 0,
  };

// crbug.com/1340245 - this causes binary size bloat on Fuchsia, and we're OK
// with not having this data in traces there.
#if !BUILDFLAG(IS_FUCHSIA)
  struct InitiateHandshake_Sym {
    NOINLINE static uint32_t IPCStableHash();
  };
  struct CompleteHandshake_Sym {
    NOINLINE static uint32_t IPCStableHash();
  };
  struct Encrypt_Sym {
    NOINLINE static uint32_t IPCStableHash();
  };
  struct Decrypt_Sym {
    NOINLINE static uint32_t IPCStableHash();
  };
#endif // !BUILDFLAG(IS_FUCHSIA)
  virtual ~OakSession() = default;

  using InitiateHandshakeCallback = base::OnceCallback<void(::private_ai::HandshakeMessage)>;
  using InitiateHandshakeMojoCallback = base::OnceCallback<void(::private_ai::HandshakeMessage)>;

  virtual void InitiateHandshake(InitiateHandshakeCallback callback) = 0;

  using CompleteHandshakeCallback = base::OnceCallback<void(bool)>;
  using CompleteHandshakeMojoCallback = base::OnceCallback<void(bool)>;

  virtual void CompleteHandshake(::private_ai::HandshakeMessage response, CompleteHandshakeCallback callback) = 0;

  using EncryptCallback = base::OnceCallback<void(const std::optional<std::vector<uint8_t>>&)>;
  using EncryptMojoCallback = base::OnceCallback<void(const std::optional<std::vector<uint8_t>>&)>;

  virtual void Encrypt(const std::vector<uint8_t>& input, EncryptCallback callback) = 0;

  using DecryptCallback = base::OnceCallback<void(const std::optional<std::vector<uint8_t>>&)>;
  using DecryptMojoCallback = base::OnceCallback<void(const std::optional<std::vector<uint8_t>>&)>;

  virtual void Decrypt(const std::vector<uint8_t>& input, DecryptCallback callback) = 0;
};



class  OakSessionProxy
    : public OakSession {
 public:
  using InterfaceType = OakSession;

  explicit OakSessionProxy(mojo::MessageReceiverWithResponder* receiver);
  
  void InitiateHandshake(InitiateHandshakeCallback callback) final;
  
  void CompleteHandshake(::private_ai::HandshakeMessage response, CompleteHandshakeCallback callback) final;
  
  void Encrypt(const std::vector<uint8_t>& input, EncryptCallback callback) final;
  
  void Decrypt(const std::vector<uint8_t>& input, DecryptCallback callback) final;

 private:
  mojo::MessageReceiverWithResponder* receiver_;
};
class  OakSessionStubDispatch {
 public:
  static bool Accept(OakSession* impl, mojo::Message* message);
  static bool AcceptWithResponder(
      OakSession* impl,
      mojo::Message* message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder);
};

template <typename ImplRefTraits =
              mojo::RawPtrImplRefTraits<OakSession>>
class OakSessionStub
    : public mojo::MessageReceiverWithResponderStatus {
 public:
  using ImplPointerType = typename ImplRefTraits::PointerType;

  OakSessionStub() = default;
  ~OakSessionStub() override = default;

  void set_sink(ImplPointerType sink) { sink_ = std::move(sink); }
  ImplPointerType& sink() { return sink_; }

  bool Accept(mojo::Message* message) override {
    if (ImplRefTraits::IsNull(sink_))
      return false;
    return OakSessionStubDispatch::Accept(
        ImplRefTraits::GetRawPointer(&sink_), message);
  }

  bool AcceptWithResponder(
      mojo::Message* message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder) override {
    if (ImplRefTraits::IsNull(sink_))
      return false;
    return OakSessionStubDispatch::AcceptWithResponder(
        ImplRefTraits::GetRawPointer(&sink_), message, std::move(responder));
  }

 private:
  ImplPointerType sink_;
};
class  OakSessionRequestValidator : public mojo::MessageReceiver {
 public:
  bool Accept(mojo::Message* message) override;
};
class  OakSessionResponseValidator : public mojo::MessageReceiver {
 public:
  bool Accept(mojo::Message* message) override;
};








class  HandshakeMessage {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<HandshakeMessage, T>::value>;
  using DataView = HandshakeMessageDataView;
  using Data_ = internal::HandshakeMessage_Data;

  template <typename... Args>
  static HandshakeMessagePtr New(Args&&... args) {
    return HandshakeMessagePtr(
        std::in_place, std::forward<Args>(args)...);
  }

  template <typename U>
  static HandshakeMessagePtr From(const U& u) {
    return mojo::TypeConverter<HandshakeMessagePtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, HandshakeMessage>::Convert(*this);
  }


  HandshakeMessage();

  HandshakeMessage(
      std::vector<uint8_t> ephemeral_public_key,
      std::vector<uint8_t> ciphertext);


  ~HandshakeMessage();

  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename StructPtrType = HandshakeMessagePtr>
  HandshakeMessagePtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        HandshakeMessage::DataView, std::vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        HandshakeMessage::DataView, std::vector<uint8_t>>(input);
  }

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        HandshakeMessage::DataView>(input);
  }

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::HandshakeMessage_UnserializedMessageContext<
            UserType, HandshakeMessage::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<HandshakeMessage::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return HandshakeMessage::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::HandshakeMessage_UnserializedMessageContext<
            UserType, HandshakeMessage::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<HandshakeMessage::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  std::vector<uint8_t> ephemeral_public_key;
  
  std::vector<uint8_t> ciphertext;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

 private:
  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);
};

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, HandshakeMessage::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}

template <typename StructPtrType>
HandshakeMessagePtr HandshakeMessage::Clone() const {
  return New(
      mojo::Clone(ephemeral_public_key),
      mojo::Clone(ciphertext)
  );
}

template <typename T, HandshakeMessage::EnableIfSame<T>*>
bool HandshakeMessage::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->ephemeral_public_key, other_struct.ephemeral_public_key))
    return false;
  if (!mojo::Equals(this->ciphertext, other_struct.ciphertext))
    return false;
  return true;
}

template <typename T, HandshakeMessage::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.ephemeral_public_key < rhs.ephemeral_public_key)
    return true;
  if (rhs.ephemeral_public_key < lhs.ephemeral_public_key)
    return false;
  if (lhs.ciphertext < rhs.ciphertext)
    return true;
  if (rhs.ciphertext < lhs.ciphertext)
    return false;
  return false;
}


}  // private_ai::mojom

namespace mojo {


template <>
struct  StructTraits<::private_ai::mojom::HandshakeMessage::DataView,
                                         ::private_ai::mojom::HandshakeMessagePtr> {
  static bool IsNull(const ::private_ai::mojom::HandshakeMessagePtr& input) { return !input; }
  static void SetToNull(::private_ai::mojom::HandshakeMessagePtr* output) { output->reset(); }

  static const decltype(::private_ai::mojom::HandshakeMessage::ephemeral_public_key)& ephemeral_public_key(
      const ::private_ai::mojom::HandshakeMessagePtr& input) {
    return input->ephemeral_public_key;
  }

  static const decltype(::private_ai::mojom::HandshakeMessage::ciphertext)& ciphertext(
      const ::private_ai::mojom::HandshakeMessagePtr& input) {
    return input->ciphertext;
  }

  static bool Read(::private_ai::mojom::HandshakeMessage::DataView input, ::private_ai::mojom::HandshakeMessagePtr* output);
};

}  // namespace mojo

#endif  // COMPONENTS_PRIVATE_AI_MOJOM_OAK_SESSION_MOJOM_H_