aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-15 17:47:22 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-15 17:47:22 +0100
commit026e4394bb333e978a37f5821f0a1c3dca6acb1d (patch)
treea06da10956a3757f6f0da3e7126777c1c2da81ea
parent6fe3b7eb73fb11e1cba27b28add5b14430b66259 (diff)
Implement creating a new account
-rw-r--r--include/axolotl/error.hh2
-rw-r--r--include/axolotl/session.hh2
-rw-r--r--src/account.cpp44
-rw-r--r--src/session.cpp2
4 files changed, 44 insertions, 6 deletions
diff --git a/include/axolotl/error.hh b/include/axolotl/error.hh
index 3bf0e63..b875784 100644
--- a/include/axolotl/error.hh
+++ b/include/axolotl/error.hh
@@ -11,6 +11,8 @@ enum struct ErrorCode {
BAD_MESSAGE_FORMAT = 4, /*!< The message couldn't be decoded */
BAD_MESSAGE_MAC = 5, /*!< The message couldn't be decrypted */
BAD_MESSAGE_KEY_ID = 6, /*!< The message references an unknown key id */
+ INVALID_BASE64 = 7, /*!< The input base64 was invalid */
+ BAD_ACCOUNT_KEY = 8, /*!< The supplied account key is invalid */
};
} // namespace axolotl
diff --git a/include/axolotl/session.hh b/include/axolotl/session.hh
index 93c0b64..aeaac7d 100644
--- a/include/axolotl/session.hh
+++ b/include/axolotl/session.hh
@@ -14,7 +14,7 @@ struct RemoteKey {
enum struct MessageType {
- PRE_KEY_MESSAGE = 0,
+ PRE_KEY = 0,
MESSAGE = 1,
};
diff --git a/src/account.cpp b/src/account.cpp
index c73ef1b..02ad5ba 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -2,7 +2,6 @@
#include "axolotl/pickle.hh"
-
axolotl::LocalKey const * axolotl::Account::lookup_key(
std::uint32_t id
) {
@@ -12,6 +11,43 @@ axolotl::LocalKey const * axolotl::Account::lookup_key(
return 0;
}
+
+std::size_t axolotl::Account::new_account_random_length() {
+ return 103 * 32;
+}
+
+std::size_t axolotl::Account::new_account(
+ uint8_t const * random, std::size_t random_length
+) {
+ if (random_length < new_account_random_length()) {
+ last_error = axolotl::ErrorCode::NOT_ENOUGH_RANDOM;
+ }
+
+ unsigned id = 0;
+
+ identity_key.id = ++id;
+ axolotl::generate_key(random, identity_key.key);
+ random += 32;
+
+ random += 32;
+
+ last_resort_one_time_key.id = ++id;
+ axolotl::generate_key(random, last_resort_one_time_key.key);
+ random += 32;
+
+ for (unsigned i = 0; i < 100; ++i) {
+ LocalKey & key = *one_time_keys.insert(one_time_keys.end());
+ key.id = ++id;
+ axolotl::generate_key(random, key.key);
+ random += 32;
+ }
+
+ return 0;
+}
+
+
+
+
namespace axolotl {
@@ -72,7 +108,7 @@ static std::uint8_t const * unpickle(
} // namespace axolotl
-std::size_t pickle_length(
+std::size_t axolotl::pickle_length(
axolotl::Account const & value
) {
std::size_t length = 0;
@@ -83,7 +119,7 @@ std::size_t pickle_length(
}
-std::uint8_t * pickle(
+std::uint8_t * axolotl::pickle(
std::uint8_t * pos,
axolotl::Account const & value
) {
@@ -94,7 +130,7 @@ std::uint8_t * pickle(
}
-std::uint8_t const * unpickle(
+std::uint8_t const * axolotl::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
axolotl::Account & value
) {
diff --git a/src/session.cpp b/src/session.cpp
index db8097f..0582d56 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -190,7 +190,7 @@ axolotl::MessageType axolotl::Session::encrypt_message_type() {
if (received_message) {
return axolotl::MessageType::MESSAGE;
} else {
- return axolotl::MessageType::PRE_KEY_MESSAGE;
+ return axolotl::MessageType::PRE_KEY;
}
}