forked from rethinkdb/rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_key.hpp
More file actions
50 lines (35 loc) · 1.32 KB
/
Copy pathauth_key.hpp
File metadata and controls
50 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2010-2013 RethinkDB, all rights reserved.
#ifndef CONTAINERS_AUTH_KEY_HPP_
#define CONTAINERS_AUTH_KEY_HPP_
#include <string>
#include "http/json/json_adapter.hpp"
#include "rpc/serialize_macros.hpp"
// A type to enforce authorization key length
class auth_key_t {
public:
// Initializes to the empty string.
auth_key_t();
// Returns true if the new key is of a valid length
MUST_USE bool assign_value(const std::string &new_key);
const std::string &str() const { return key; }
static const int32_t max_length = 2048;
private:
std::string key;
RDB_DECLARE_ME_SERIALIZABLE;
};
bool timing_sensitive_equals(const auth_key_t &x, const auth_key_t &y);
inline bool operator==(const auth_key_t &x, const auth_key_t &y) {
// Might as well use timing_sensitive_equals this in case of accidental misuse.
return timing_sensitive_equals(x, y);
}
inline bool operator!=(const auth_key_t &x, const auth_key_t &y) {
return !(x == y);
}
inline bool operator<(const auth_key_t &x, const auth_key_t &y) {
return x.str() < y.str();
}
// ctx-less json adapter concept for auth_key_t
json_adapter_if_t::json_adapter_map_t get_json_subfields(auth_key_t *target);
cJSON *render_as_json(auth_key_t *target);
void apply_json_to(cJSON *change, auth_key_t *target);
#endif // CONTAINERS_AUTH_KEY_HPP_