diff options
author | Jack Lloyd <[email protected]> | 2017-10-03 00:38:15 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-10-03 00:38:15 -0400 |
commit | 04d64c3e0fe60a25b1f1a5c2eaf7e2986d2130dd (patch) | |
tree | 3dc2cc7e970fc5f1cdc94887b03704d82c37e07e /src/lib/tls | |
parent | 180540de74c58a72492692f58b63f32647e80bd8 (diff) |
Add wrappers for reinterpret_cast between char* and uint8_t*
Generally speaking reinterpret_cast is sketchy stuff. But the
special case of char*/uint8_t* is both common and safe. By
isolating those, the remaining (likely sketchy) cases are easier
to grep for.
Diffstat (limited to 'src/lib/tls')
-rw-r--r-- | src/lib/tls/tls_channel.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_extensions.cpp | 8 | ||||
-rw-r--r-- | src/lib/tls/tls_reader.h | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp index 034976ec4..78f681765 100644 --- a/src/lib/tls/tls_channel.cpp +++ b/src/lib/tls/tls_channel.cpp @@ -548,7 +548,7 @@ void Channel::send(const uint8_t buf[], size_t buf_size) void Channel::send(const std::string& string) { - this->send(reinterpret_cast<const uint8_t*>(string.c_str()), string.size()); + this->send(cast_char_ptr_to_uint8(string.data()), string.size()); } void Channel::send_alert(const Alert& alert) diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index c76128632..317d96b8d 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -178,7 +178,7 @@ std::vector<uint8_t> Server_Name_Indicator::serialize() const buf.push_back(get_byte(1, static_cast<uint16_t>(name_len))); buf += std::make_pair( - reinterpret_cast<const uint8_t*>(m_sni_host_name.data()), + cast_char_ptr_to_uint8(m_sni_host_name.data()), m_sni_host_name.size()); return buf; @@ -197,9 +197,7 @@ std::vector<uint8_t> SRP_Identifier::serialize() const { std::vector<uint8_t> buf; - const uint8_t* srp_bytes = - reinterpret_cast<const uint8_t*>(m_srp_identifier.data()); - + const uint8_t* srp_bytes = cast_char_ptr_to_uint8(m_srp_identifier.data()); append_tls_length_value(buf, srp_bytes, m_srp_identifier.size(), 1); return buf; @@ -266,7 +264,7 @@ std::vector<uint8_t> Application_Layer_Protocol_Notification::serialize() const throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long"); if(p != "") append_tls_length_value(buf, - reinterpret_cast<const uint8_t*>(p.data()), + cast_char_ptr_to_uint8(p.data()), p.size(), 1); } diff --git a/src/lib/tls/tls_reader.h b/src/lib/tls/tls_reader.h index 588335144..8474f1308 100644 --- a/src/lib/tls/tls_reader.h +++ b/src/lib/tls/tls_reader.h @@ -119,7 +119,7 @@ class TLS_Data_Reader final std::vector<uint8_t> v = get_range_vector<uint8_t>(len_bytes, min_bytes, max_bytes); - return std::string(reinterpret_cast<char*>(v.data()), v.size()); + return std::string(cast_uint8_ptr_to_char(v.data()), v.size()); } template<typename T> @@ -219,7 +219,7 @@ void append_tls_length_value(std::vector<uint8_t, Alloc>& buf, size_t tag_size) { append_tls_length_value(buf, - reinterpret_cast<const uint8_t*>(str.data()), + cast_char_ptr_to_uint8(str.data()), str.size(), tag_size); } |