tls.h 819 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. /*
  3. * TLS client implementation using GnuTLS
  4. * Dependencies: bzbnet, GnuTLS
  5. */
  6. #include "socket.h"
  7. namespace bzbnet {
  8. constexpr unsigned int DEFAULT_TLS_PACKETSIZE = 512;
  9. /*
  10. * Initializes te GnuTLS library and credentials structure.
  11. * TLSClient calls this function automatically.
  12. */
  13. void initialize_tls();
  14. /*
  15. * Destroys the GnuTLS library and credentials structure.
  16. */
  17. void destroy_tls();
  18. class TLSClient {
  19. private:
  20. TCPSocket socket;
  21. void* session_ptr;
  22. public:
  23. TLSClient();
  24. ~TLSClient();
  25. void connect(std::string hostname, std::string service = "443");
  26. std::vector<char> recv(unsigned int packetsize = DEFAULT_TLS_PACKETSIZE);
  27. void send(std::string data);
  28. void send(std::vector<char> data);
  29. void close();
  30. bool is_open();
  31. int get_raw_fd();
  32. };
  33. }