aboutsummaryrefslogtreecommitdiff
path: root/src/message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/message.cpp')
-rw-r--r--src/message.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/message.cpp b/src/message.cpp
index 93473b9..05f707f 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -17,7 +17,7 @@
namespace {
template<typename T>
-std::size_t varint_length(
+static std::size_t varint_length(
T value
) {
std::size_t result = 1;
@@ -30,7 +30,7 @@ std::size_t varint_length(
template<typename T>
-std::uint8_t * varint_encode(
+static std::uint8_t * varint_encode(
std::uint8_t * output,
T value
) {
@@ -44,11 +44,14 @@ std::uint8_t * varint_encode(
template<typename T>
-T varint_decode(
+static T varint_decode(
std::uint8_t const * varint_start,
std::uint8_t const * varint_end
) {
T value = 0;
+ if (varint_end == varint_start) {
+ return 0;
+ }
do {
value <<= 7;
value |= 0x7F & *(--varint_end);
@@ -57,7 +60,7 @@ T varint_decode(
}
-std::uint8_t const * varint_skip(
+static std::uint8_t const * varint_skip(
std::uint8_t const * input,
std::uint8_t const * input_end
) {
@@ -71,7 +74,7 @@ std::uint8_t const * varint_skip(
}
-std::size_t varstring_length(
+static std::size_t varstring_length(
std::size_t string_length
) {
return varint_length(string_length) + string_length;
@@ -82,7 +85,7 @@ static std::uint8_t const RATCHET_KEY_TAG = 012;
static std::uint8_t const COUNTER_TAG = 020;
static std::uint8_t const CIPHERTEXT_TAG = 042;
-std::uint8_t * encode(
+static std::uint8_t * encode(
std::uint8_t * pos,
std::uint8_t tag,
std::uint32_t value
@@ -91,7 +94,7 @@ std::uint8_t * encode(
return varint_encode(pos, value);
}
-std::uint8_t * encode(
+static std::uint8_t * encode(
std::uint8_t * pos,
std::uint8_t tag,
std::uint8_t * & value, std::size_t value_length
@@ -102,7 +105,7 @@ std::uint8_t * encode(
return pos + value_length;
}
-std::uint8_t const * decode(
+static std::uint8_t const * decode(
std::uint8_t const * pos, std::uint8_t const * end,
std::uint8_t tag,
std::uint32_t & value, bool & has_value
@@ -118,7 +121,7 @@ std::uint8_t const * decode(
}
-std::uint8_t const * decode(
+static std::uint8_t const * decode(
std::uint8_t const * pos, std::uint8_t const * end,
std::uint8_t tag,
std::uint8_t const * & value, std::size_t & value_length
@@ -136,7 +139,7 @@ std::uint8_t const * decode(
return pos;
}
-std::uint8_t const * skip_unknown(
+static std::uint8_t const * skip_unknown(
std::uint8_t const * pos, std::uint8_t const * end
) {
if (pos != end) {
@@ -201,13 +204,17 @@ void olm::decode_message(
std::uint8_t const * end = input + input_length - mac_length;
std::uint8_t const * unknown = nullptr;
- if (pos == end) return;
- reader.version = *(pos++);
reader.input = input;
reader.input_length = input_length;
reader.has_counter = false;
reader.ratchet_key = nullptr;
+ reader.ratchet_key_length = 0;
reader.ciphertext = nullptr;
+ reader.ciphertext_length = 0;
+
+ if (pos == end) return;
+ if (input_length < mac_length) return;
+ reader.version = *(pos++);
while (pos != end) {
pos = decode(
@@ -281,12 +288,17 @@ void olm::decode_one_time_key_message(
std::uint8_t const * end = input + input_length;
std::uint8_t const * unknown = nullptr;
- if (pos == end) return;
- reader.version = *(pos++);
reader.one_time_key = nullptr;
+ reader.one_time_key_length = 0;
reader.identity_key = nullptr;
+ reader.identity_key_length = 0;
reader.base_key = nullptr;
+ reader.base_key_length = 0;
reader.message = nullptr;
+ reader.message_length = 0;
+
+ if (pos == end) return;
+ reader.version = *(pos++);
while (pos != end) {
pos = decode(