account.hh 1.44 KB
Newer Older
1
2
3
4
#ifndef AXOLOTL_ACCOUNT_HH_
#define AXOLOTL_ACCOUNT_HH_

#include "axolotl/list.hh"
5
6
#include "axolotl/crypto.hh"
#include "axolotl/error.hh"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <cstdint>

namespace axolotl {


struct LocalKey {
    std::uint32_t id;
    Curve25519KeyPair key;
};


struct SignedKey : LocalKey {
    std::uint8_t signature[64];
};


static std::size_t const MAX_ONE_TIME_KEYS = 100;

struct Account {
    LocalKey identity_key;
    LocalKey last_resort_one_time_key;
    List<LocalKey, MAX_ONE_TIME_KEYS> one_time_keys;
30
    ErrorCode last_error;
31
32
33
34
35
36

    /** Number of random bytes needed to create a new account */
    std::size_t new_account_random_length();

    /** Create a new account. Returns NOT_ENOUGH_RANDOM if the number of random
     * bytes is too small. */
37
    std::size_t new_account(
38
39
40
        uint8_t const * random, std::size_t random_length
    );

41
42
43
44
    LocalKey const * lookup_key(
        std::uint32_t id
    );

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    /** The number of bytes needed to persist this account. */
    std::size_t pickle_length();

    /** Persists an account as a sequence of bytes
     * Returns the number of output bytes used. */
    std::size_t pickle(
        std::uint8_t * output, std::size_t output_length
    );

    /** Loads an account from a sequence of bytes.
     * Returns 0 on success, or std::size_t(-1) on failure. */
    std::size_t unpickle(
        std::uint8_t * input, std::size_t input_length
    );
};


} // namespace axolotl

#endif /* AXOLOTL_ACCOUNT_HH_ */