Implement creating a new account

This commit is contained in:
Mark Haines 2015-06-15 17:47:22 +01:00
parent 6fe3b7eb73
commit 026e4394bb
4 changed files with 44 additions and 6 deletions

View file

@ -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

View file

@ -14,7 +14,7 @@ struct RemoteKey {
enum struct MessageType {
PRE_KEY_MESSAGE = 0,
PRE_KEY = 0,
MESSAGE = 1,
};

View file

@ -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
) {

View file

@ -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;
}
}