aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/tls
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2022-04-04 15:06:29 +0200
committerRenĂ© Meusel <[email protected]>2022-04-04 15:06:29 +0200
commita20f2471fee0da63560fc698a1c5f4c0e4b5fe40 (patch)
tree1100950707bb5f0e9a8b3693b41ef5ae245a18a1 /src/lib/tls
parente52d3301ee3e98020c74263dfedb231ca7c83ca2 (diff)
Additional convenience methods for TLS_Data_Reader
Co-Authored-By: Hannes Rantzsch <[email protected]>
Diffstat (limited to 'src/lib/tls')
-rw-r--r--src/lib/tls/tls_reader.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lib/tls/tls_reader.h b/src/lib/tls/tls_reader.h
index d31bf7ef4..6bd5b7e6b 100644
--- a/src/lib/tls/tls_reader.h
+++ b/src/lib/tls/tls_reader.h
@@ -64,6 +64,15 @@ class TLS_Data_Reader final
return result;
}
+ uint32_t get_uint24_t()
+ {
+ assert_at_least(3);
+ uint32_t result = make_uint32(0, m_buf[m_offset],
+ m_buf[m_offset+1], m_buf[m_offset+2]);
+ m_offset += 3;
+ return result;
+ }
+
uint16_t get_uint16_t()
{
assert_at_least(2);
@@ -72,6 +81,12 @@ class TLS_Data_Reader final
return result;
}
+ uint16_t peek_uint16_t() const
+ {
+ assert_at_least(2);
+ return make_uint16(m_buf[m_offset], m_buf[m_offset+1]);
+ }
+
uint8_t get_byte()
{
assert_at_least(1);
@@ -95,6 +110,11 @@ class TLS_Data_Reader final
return result;
}
+ std::vector<uint8_t> get_tls_length_value(size_t len_bytes)
+ {
+ return get_fixed<uint8_t>(get_length_field(len_bytes));
+ }
+
template<typename T>
std::vector<T> get_range(size_t len_bytes,
size_t min_elems,
@@ -142,6 +162,8 @@ class TLS_Data_Reader final
return get_byte();
else if(len_bytes == 2)
return get_uint16_t();
+ else if(len_bytes == 3)
+ return get_uint24_t();
throw decode_error("Bad length size");
}
@@ -195,11 +217,12 @@ void append_tls_length_value(std::vector<uint8_t, Alloc>& buf,
const size_t T_size = sizeof(T);
const size_t val_bytes = T_size * vals_size;
- if(tag_size != 1 && tag_size != 2)
+ if(tag_size != 1 && tag_size != 2 && tag_size != 3)
throw Invalid_Argument("append_tls_length_value: invalid tag size");
if((tag_size == 1 && val_bytes > 255) ||
- (tag_size == 2 && val_bytes > 65535))
+ (tag_size == 2 && val_bytes > 65535) ||
+ (tag_size == 3 && val_bytes > 16777215))
throw Invalid_Argument("append_tls_length_value: value too large");
for(size_t i = 0; i != tag_size; ++i)