ShannonConnection.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef SHANNONCONNECTION_H
  2. #define SHANNONCONNECTION_H
  3. #include <cstdint> // for uint8_t, uint32_t
  4. #include <memory> // for shared_ptr, unique_ptr
  5. #include <mutex> // for mutex
  6. #include <vector> // for vector
  7. #include "Packet.h" // for Packet
  8. class Shannon;
  9. namespace cspot {
  10. class PlainConnection;
  11. } // namespace cspot
  12. #define MAC_SIZE 4
  13. namespace cspot {
  14. class ShannonConnection {
  15. private:
  16. std::unique_ptr<Shannon> sendCipher;
  17. std::unique_ptr<Shannon> recvCipher;
  18. uint32_t sendNonce = 0;
  19. uint32_t recvNonce = 0;
  20. std::vector<uint8_t> cipherPacket(uint8_t cmd, std::vector<uint8_t>& data);
  21. std::mutex writeMutex;
  22. std::mutex readMutex;
  23. public:
  24. ShannonConnection();
  25. ~ShannonConnection();
  26. void wrapConnection(std::shared_ptr<PlainConnection> conn,
  27. std::vector<uint8_t>& sendKey,
  28. std::vector<uint8_t>& recvKey);
  29. void sendPacket(uint8_t cmd, std::vector<uint8_t>& data);
  30. std::shared_ptr<PlainConnection> conn;
  31. Packet recvPacket();
  32. };
  33. } // namespace cspot
  34. #endif