ssl_backend.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "core/hle/result.h"
  5. #include "common/common_types.h"
  6. #include <memory>
  7. #include <span>
  8. #include <string>
  9. #include <vector>
  10. namespace Network {
  11. class SocketBase;
  12. }
  13. namespace Service::SSL {
  14. constexpr Result ResultNoSocket{ErrorModule::SSLSrv, 103};
  15. constexpr Result ResultInvalidSocket{ErrorModule::SSLSrv, 106};
  16. constexpr Result ResultTimeout{ErrorModule::SSLSrv, 205};
  17. constexpr Result ResultInternalError{ErrorModule::SSLSrv, 999}; // made up
  18. // ResultWouldBlock is returned from Read and Write, and oddly, DoHandshake,
  19. // with no way in the latter case to distinguish whether the client should poll
  20. // for read or write. The one official client I've seen handles this by always
  21. // polling for read (with a timeout).
  22. constexpr Result ResultWouldBlock{ErrorModule::SSLSrv, 204};
  23. class SSLConnectionBackend {
  24. public:
  25. virtual ~SSLConnectionBackend() {}
  26. virtual void SetSocket(std::shared_ptr<Network::SocketBase> socket) = 0;
  27. virtual Result SetHostName(const std::string& hostname) = 0;
  28. virtual Result DoHandshake() = 0;
  29. virtual ResultVal<size_t> Read(std::span<u8> data) = 0;
  30. virtual ResultVal<size_t> Write(std::span<const u8> data) = 0;
  31. virtual ResultVal<std::vector<std::vector<u8>>> GetServerCerts() = 0;
  32. };
  33. ResultVal<std::unique_ptr<SSLConnectionBackend>> CreateSSLConnectionBackend();
  34. } // namespace Service::SSL