aboutsummaryrefslogtreecommitdiff
path: root/src/account.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-12 16:15:37 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-12 16:15:37 +0100
commit6fe3b7eb73fb11e1cba27b28add5b14430b66259 (patch)
treee2e526e4f5593cb8d978f1b8955b80c9c2d88b4e /src/account.cpp
parent28541dd82a9e4a99661ba32905b8488d35e70fe3 (diff)
Move utils for pickling into a separate file
Diffstat (limited to 'src/account.cpp')
-rw-r--r--src/account.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/account.cpp b/src/account.cpp
new file mode 100644
index 0000000..c73ef1b
--- /dev/null
+++ b/src/account.cpp
@@ -0,0 +1,105 @@
+#include "axolotl/account.hh"
+#include "axolotl/pickle.hh"
+
+
+
+axolotl::LocalKey const * axolotl::Account::lookup_key(
+ std::uint32_t id
+) {
+ for (axolotl::LocalKey const & key : one_time_keys) {
+ if (key.id == id) return &key;
+ }
+ return 0;
+}
+
+namespace axolotl {
+
+
+static std::size_t pickle_length(
+ axolotl::LocalKey const & value
+) {
+ return axolotl::pickle_length(value.id) + axolotl::pickle_length(value.key);
+}
+
+
+static std::uint8_t * pickle(
+ std::uint8_t * pos,
+ axolotl::LocalKey const & value
+) {
+ pos = axolotl::pickle(pos, value.id);
+ pos = axolotl::pickle(pos, value.key);
+ return pos;
+}
+
+
+static std::uint8_t const * unpickle(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ axolotl::LocalKey & value
+) {
+ pos = axolotl::unpickle(pos, end, value.id);
+ pos = axolotl::unpickle(pos, end, value.key);
+ return pos;
+}
+
+
+static std::size_t pickle_length(
+ axolotl::SignedKey const & value
+) {
+ return axolotl::pickle_length((axolotl::LocalKey const &) value) + 64;
+}
+
+
+static std::uint8_t * pickle(
+ std::uint8_t * pos,
+ axolotl::SignedKey const & value
+) {
+ pos = axolotl::pickle(pos, (axolotl::LocalKey const &) value);
+ pos = axolotl::pickle_bytes(pos, value.signature, 64);
+ return pos;
+}
+
+
+static std::uint8_t const * unpickle(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ axolotl::SignedKey & value
+) {
+ pos = axolotl::unpickle(pos, end, (axolotl::LocalKey &) value);
+ pos = axolotl::unpickle_bytes(pos, end, value.signature, 64);
+ return pos;
+}
+
+
+} // namespace axolotl
+
+
+std::size_t pickle_length(
+ axolotl::Account const & value
+) {
+ std::size_t length = 0;
+ length += axolotl::pickle_length(value.identity_key);
+ length += axolotl::pickle_length(value.last_resort_one_time_key);
+ length += axolotl::pickle_length(value.one_time_keys);
+ return length;
+}
+
+
+std::uint8_t * pickle(
+ std::uint8_t * pos,
+ axolotl::Account const & value
+) {
+ pos = axolotl::pickle(pos, value.identity_key);
+ pos = axolotl::pickle(pos, value.last_resort_one_time_key);
+ pos = axolotl::pickle(pos, value.one_time_keys);
+ return pos;
+}
+
+
+std::uint8_t const * unpickle(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ axolotl::Account & value
+) {
+ pos = axolotl::unpickle(pos, end, value.identity_key);
+ pos = axolotl::unpickle(pos, end, value.last_resort_one_time_key);
+ pos = axolotl::unpickle(pos, end, value.one_time_keys);
+ return pos;
+}