17 #ifndef CONNECTMESSAGE_HPP_
18 #define CONNECTMESSAGE_HPP_
23 #include <botan/botan.h>
27 #include <arpa/inet.h>
35 template<
class T,
class U,
class V>
37 std::uint32_t nextProtocolId,
40 const V& payload) : message_(0)
49 std::copy(reinterpret_cast<const std::uint8_t *>(header),
50 reinterpret_cast<const std::uint8_t *>(header + size),
53 auto messageIt = message_.begin() + size;
56 std::copy(reinterpret_cast<std::uint8_t *>(&nameLengthNetworkOrder), reinterpret_cast<std::uint8_t *>(&nameLengthNetworkOrder) + 2, messageIt);
57 messageIt +=
sizeof(std::uint16_t);
64 *(messageIt++) = 0x02;
66 std::uint32_t nextProtocolIdNetworkOrder = htonl(nextProtocolId);
67 std::copy(reinterpret_cast<std::uint8_t *>(&nextProtocolIdNetworkOrder), reinterpret_cast<std::uint8_t *>(&nextProtocolIdNetworkOrder) + 4, messageIt);
68 messageIt +=
sizeof(std::uint32_t);
73 std::uint16_t timerNetworkOrder = htons(timer);
74 std::copy(reinterpret_cast<std::uint8_t *>(&timerNetworkOrder), reinterpret_cast<std::uint8_t *>(&timerNetworkOrder) + 2, messageIt);
75 messageIt +=
sizeof(std::uint16_t);
77 std::copy(sessionKey.begin(), sessionKey.end(), messageIt);
78 messageIt += sessionKey.size();
80 std::copy(signature.begin(), signature.end(), messageIt);
81 messageIt += signature.size();
83 std::copy(payload.begin(), payload.end(), messageIt);
87 const std::vector<std::uint8_t>&
getRawMessage()
const {
return message_; }
90 std::vector<std::uint8_t> message_;
static const std::uint8_t KAA_CONNECT_SESSION_KEY_FLAGS
static const std::uint8_t KAA_CONNECT_HEADER_LENGTH
const std::vector< std::uint8_t > & getRawMessage() const
static const std::uint8_t KAA_CONNECT_SIGNATURE_FLAGS
ConnectMessage(std::uint16_t timer, std::uint32_t nextProtocolId, const T &signature, const U &sessionKey, const V &payload)
static const std::uint8_t PROTOCOL_VERSION
static const std::uint16_t KAA_TCP_NAME_LENGTH
static const char *const KAA_TCP_NAME
static std::uint8_t createBasicHeader(std::uint8_t messageType, std::uint32_t length, char *message)