diff options
Diffstat (limited to 'src/components/security_manager/src/security_query.cc')
-rw-r--r-- | src/components/security_manager/src/security_query.cc | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/src/components/security_manager/src/security_query.cc b/src/components/security_manager/src/security_query.cc index cd4da03c15..60233dde5e 100644 --- a/src/components/security_manager/src/security_query.cc +++ b/src/components/security_manager/src/security_query.cc @@ -38,35 +38,37 @@ namespace security_manager { SecurityQuery::QueryHeader::QueryHeader() - : query_type(INVALID_QUERY_TYPE), query_id(INVALID_QUERY_ID), - seq_number(0), json_size(0) { -} - -SecurityQuery::QueryHeader::QueryHeader(uint8_t queryType, uint32_t queryId, - uint32_t seqNumber, uint32_t jsonSize) - : query_type(queryType), query_id(queryId), - seq_number(seqNumber), json_size(jsonSize) { -} + : query_type(INVALID_QUERY_TYPE) + , query_id(INVALID_QUERY_ID) + , seq_number(0) + , json_size(0) {} + +SecurityQuery::QueryHeader::QueryHeader(uint8_t queryType, + uint32_t queryId, + uint32_t seqNumber, + uint32_t jsonSize) + : query_type(queryType) + , query_id(queryId) + , seq_number(seqNumber) + , json_size(jsonSize) {} SecurityQuery::SecurityQuery() - : header_(INVALID_QUERY_TYPE, INVALID_QUERY_ID, 0), connection_key_(0) { -} + : header_(INVALID_QUERY_TYPE, INVALID_QUERY_ID, 0), connection_key_(0) {} -SecurityQuery::SecurityQuery(const SecurityQuery::QueryHeader &header, +SecurityQuery::SecurityQuery(const SecurityQuery::QueryHeader& header, const uint32_t connection_key, - const uint8_t *const raw_data, + const uint8_t* const raw_data, const size_t raw_data_size) - : header_(header), connection_key_(connection_key), - data_(raw_data, raw_data + raw_data_size) { -} + : header_(header) + , connection_key_(connection_key) + , data_(raw_data, raw_data + raw_data_size) {} -SecurityQuery::SecurityQuery(const SecurityQuery::QueryHeader &header, +SecurityQuery::SecurityQuery(const SecurityQuery::QueryHeader& header, const uint32_t connection_key) - : header_(header), connection_key_(connection_key) { -} + : header_(header), connection_key_(connection_key) {} -bool SecurityQuery::SerializeQuery(const uint8_t *const raw_data, - const size_t raw_data_size) { +bool SecurityQuery::SerializeQuery(const uint8_t* const raw_data, + const size_t raw_data_size) { const size_t header_size = sizeof(QueryHeader); if (raw_data_size < header_size || !raw_data) { return false; @@ -74,21 +76,21 @@ bool SecurityQuery::SerializeQuery(const uint8_t *const raw_data, const uint8_t query_type = raw_data[0]; switch (query_type) { case REQUEST: - header_.query_type = REQUEST; + header_.query_type = REQUEST; break; case RESPONSE: - header_.query_type = RESPONSE; + header_.query_type = RESPONSE; break; case NOTIFICATION: - header_.query_type = NOTIFICATION; + header_.query_type = NOTIFICATION; break; default: header_.query_type = INVALID_QUERY_TYPE; break; } // Convert to Little-Endian and clean high byte - const uint32_t query_id = 0x00FFFFFF & - BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data)); + const uint32_t query_id = + 0x00FFFFFF & BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data)); switch (query_id) { case SEND_HANDSHAKE_DATA: header_.query_id = SEND_HANDSHAKE_DATA; @@ -100,22 +102,25 @@ bool SecurityQuery::SerializeQuery(const uint8_t *const raw_data, header_.query_id = INVALID_QUERY_ID; break; } - header_.seq_number = BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data + 4)); - header_.json_size = BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data + 8)); + header_.seq_number = + BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data + 4)); + header_.json_size = + BE_TO_LE32(*reinterpret_cast<const uint32_t*>(raw_data + 8)); if (header_.json_size > raw_data_size - header_size) return false; if (header_.json_size > 0) { - const char *const json_data = + const char* const json_data = reinterpret_cast<const char*>(raw_data + header_size); json_message_.assign(json_data, json_data + header_.json_size); } - const uint32_t bin_data_size = raw_data_size - (header_size + header_.json_size); + const uint32_t bin_data_size = + raw_data_size - (header_size + header_.json_size); if (bin_data_size > 0) { - const char *const bin_data = - reinterpret_cast<const char*>(raw_data + header_size + header_.json_size); + const char* const bin_data = reinterpret_cast<const char*>( + raw_data + header_size + header_.json_size); data_.assign(bin_data, bin_data + bin_data_size); } return true; @@ -124,31 +129,33 @@ bool SecurityQuery::SerializeQuery(const uint8_t *const raw_data, const std::vector<uint8_t> SecurityQuery::DeserializeQuery() const { SecurityQuery::QueryHeader deserialize_header(header_); const uint32_t tmp = deserialize_header.query_id << 8; - deserialize_header.query_id = LE_TO_BE32(tmp); + deserialize_header.query_id = LE_TO_BE32(tmp); deserialize_header.seq_number = LE_TO_BE32(deserialize_header.seq_number); - deserialize_header.json_size = LE_TO_BE32(deserialize_header.json_size); + deserialize_header.json_size = LE_TO_BE32(deserialize_header.json_size); const size_t header_size = sizeof(deserialize_header); // vector of header and raw_data - std::vector<uint8_t> data_sending(header_size + data_.size() + json_message_.size()); + std::vector<uint8_t> data_sending(header_size + data_.size() + + json_message_.size()); // copy header memcpy(&data_sending[0], &deserialize_header, header_size); // copy binary data std::copy(data_.begin(), data_.end(), data_sending.begin() + header_size); // copy text (json) data - std::copy(json_message_.begin(), json_message_.end(), + std::copy(json_message_.begin(), + json_message_.end(), data_sending.begin() + header_size + data_.size()); return data_sending; } -void SecurityQuery::set_data(const uint8_t *const binary_data, - const size_t bin_data_size) { - DCHECK(binary_data); - DCHECK(bin_data_size); - data_.assign(binary_data, binary_data + bin_data_size); +void SecurityQuery::set_data(const uint8_t* const binary_data, + const size_t bin_data_size) { + DCHECK(binary_data); + DCHECK(bin_data_size); + data_.assign(binary_data, binary_data + bin_data_size); } -void SecurityQuery::set_json_message(const std::string &json_message) { +void SecurityQuery::set_json_message(const std::string& json_message) { json_message_ = json_message; } @@ -156,11 +163,11 @@ void SecurityQuery::set_connection_key(const uint32_t connection_key) { connection_key_ = connection_key; } -void SecurityQuery::set_header(const SecurityQuery::QueryHeader &header) { +void SecurityQuery::set_header(const SecurityQuery::QueryHeader& header) { header_ = header; } -const SecurityQuery::QueryHeader &SecurityQuery::get_header() const { +const SecurityQuery::QueryHeader& SecurityQuery::get_header() const { return header_; } @@ -172,7 +179,7 @@ size_t SecurityQuery::get_data_size() const { return data_.size(); } -const std::string &SecurityQuery::get_json_message() const { +const std::string& SecurityQuery::get_json_message() const { return json_message_; } |