14#ifndef OPENVPN_COMMON_SESS_ID_H
15#define OPENVPN_COMMON_SESS_ID_H
42 static_assert(
sizeof(
u.data) >=
sizeof(std::uint64_t),
"SessionIDType SIZE too small");
43 static_assert(SIZE %
sizeof(std::uint64_t) ==
size_t(0),
"SessionIDType SIZE must be an integer multiple of 64 bits");
44 std::memset(
u.data, 0,
sizeof(
u.data));
56 Buffer srcbuf(
u.data,
sizeof(
u.data),
false);
61 catch (
const std::exception &e)
63 throw Exception(
"SessionID: base64 decode: " + std::string(e.what()));
65 if (srcbuf.
size() !=
sizeof(
u.data))
66 throw Exception(
"SessionID: wrong input size, actual=" + std::to_string(srcbuf.
size()) +
" expected=" + std::to_string(
sizeof(
u.data)));
72 std::memcpy(
u.data, bytes, SIZE);
87 template <
typename CRYPT>
90 crypt(
u.data, other.
u.
data, SIZE);
108 template <
typename HASH>
122 return std::memcmp(
u.data, other.
u.
data,
sizeof(
u.data)) == 0;
132 return std::memcmp(
u.data, other.
u.
data,
sizeof(
u.data)) < 0;
143 static bool is(
const std::string &str)
162 template <
typename UNORDERED_MAP>
165 if (m.bucket_count())
167 const size_t bi = m.bucket(*
this);
168 for (
auto i = m.cbegin(bi); i != m.cend(bi); ++i)
169 if (
shortform() == i->first.shortform() && (!conflict || *
this != i->first))
177 std::uint64_t
dataz[SIZE /
sizeof(std::uint64_t)];
bool is_base64(const V &data, const size_t expected_decoded_length) const
std::string encode(const V &data) const
size_t decode(void *data, size_t len, const std::string &str) const
size_t size() const
Returns the size of the buffer in T objects.
virtual void rand_bytes(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes.
SessionIDType(const SessionIDType &other, CRYPT &crypt)
SessionIDType(const SessionIDType< S > &other)
bool operator<(const SessionIDType &other) const
std::string to_string() const
bool operator==(const SessionIDType &other) const
std::uint64_t shortform() const
bool eq_weak(const SessionIDType< S > &other) const
bool operator!=(const SessionIDType &other) const
union openvpn::SessionIDType::@23 u
static constexpr size_t size()
SessionIDType(const std::string &b64)
std::uint64_t dataz[SIZE/sizeof(std::uint64_t)]
const SessionIDType * find_weak(const UNORDERED_MAP &m, const bool conflict) const
static bool is(const std::string &str)
const std::uint8_t * c_data() const
SessionIDType(StrongRandomAPI &rng)
SessionIDType(const std::uint8_t *bytes)
Abstract base class for cryptographically strong random number generators.
#define OPENVPN_HASH_METHOD(T, meth)
Support deferred server-side state creation when client connects.
std::string to_string(T value)
constexpr std::size_t array_size(T(&)[N])
const Base64 * base64_urlsafe
SessionIDType< 16 > SessionID128
SessionIDType< 8 > SessionID64
#define OPENVPN_OSTREAM(TYPE, METH)
Implementation of the base classes for random number generators.