account.hh 1.74 KB
Newer Older
Mark Haines's avatar
Mark Haines committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* Copyright 2015 OpenMarket Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
15
16
#ifndef OLM_ACCOUNT_HH_
#define OLM_ACCOUNT_HH_
17

18
19
20
#include "olm/list.hh"
#include "olm/crypto.hh"
#include "olm/error.hh"
21
22
23

#include <cstdint>

24
namespace olm {
25
26
27
28
29
30
31
32
33
34
35
36
37
38


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


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;
39
    ErrorCode last_error;
40
41
42
43
44
45

    /** 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. */
46
    std::size_t new_account(
47
48
49
        uint8_t const * random, std::size_t random_length
    );

50
51
52
    LocalKey const * lookup_key(
        std::uint32_t id
    );
53
54
55
56

    std::size_t remove_key(
        std::uint32_t id
    );
57
};
58

59

60
61
62
std::size_t pickle_length(
    Account const & value
);
63

64
65
66
67
68
69
70
71
72
73
74

std::uint8_t * pickle(
    std::uint8_t * pos,
    Account const & value
);


std::uint8_t const * unpickle(
    std::uint8_t const * pos, std::uint8_t const * end,
    Account & value
);
75
76


77
} // namespace olm
78

79
#endif /* OLM_ACCOUNT_HH_ */