aboutsummaryrefslogtreecommitdiff
path: root/src/account.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-10 18:00:18 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-10 18:00:18 +0100
commit5ad929104e4db4b788c3792bca3e7d02283dc77e (patch)
treece36f53e86e1c4ac654c65ee630d53a4e45a8a56 /src/account.cpp
parentb6e248c9a58cccbcd5dea7bdc8e3cdee4af03722 (diff)
Version the pickled objects and check for errors when unpickling them
Diffstat (limited to 'src/account.cpp')
-rw-r--r--src/account.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/account.cpp b/src/account.cpp
index 796b06e..cf6f0cb 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -360,11 +360,16 @@ static std::uint8_t const * unpickle(
} // namespace olm
+namespace {
+static const std::uint32_t ACCOUNT_PICKLE_VERSION = 1;
+}
+
std::size_t olm::pickle_length(
olm::Account const & value
) {
std::size_t length = 0;
+ length += olm::pickle_length(ACCOUNT_PICKLE_VERSION);
length += olm::pickle_length(value.identity_keys);
length += olm::pickle_length(value.one_time_keys);
length += olm::pickle_length(value.next_one_time_key_id);
@@ -376,6 +381,7 @@ std::uint8_t * olm::pickle(
std::uint8_t * pos,
olm::Account const & value
) {
+ pos = olm::pickle(pos, ACCOUNT_PICKLE_VERSION);
pos = olm::pickle(pos, value.identity_keys);
pos = olm::pickle(pos, value.one_time_keys);
pos = olm::pickle(pos, value.next_one_time_key_id);
@@ -387,6 +393,12 @@ std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
olm::Account & value
) {
+ uint32_t pickle_version;
+ pos = olm::unpickle(pos, end, pickle_version);
+ if (pickle_version != ACCOUNT_PICKLE_VERSION) {
+ value.last_error = olm::ErrorCode::UNKNOWN_PICKLE_VERSION;
+ return end;
+ }
pos = olm::unpickle(pos, end, value.identity_keys);
pos = olm::unpickle(pos, end, value.one_time_keys);
pos = olm::unpickle(pos, end, value.next_one_time_key_id);