14#ifndef OPENVPN_CRYPTO_STATIC_KEY_H
15#define OPENVPN_CRYPTO_STATIC_KEY_H
39 StaticKey(
const unsigned char *key_data,
const size_t key_size)
54 const unsigned char *
data()
const
135 throw static_key_bad_size();
136 static const unsigned char key_table[] = {0, 1, 2, 3, 2, 3, 0, 1};
137 const unsigned int idx = key_table[key_specifier & 7] * 64;
143 const std::string str =
read_text(filename);
151 bool in_body =
false;
154 const std::string &line = in.
line_ref();
162 if (in_body || data.size() !=
KEY_SIZE)
163 throw static_key_parse_error();
170 throw static_key_bad_size();
171 std::ostringstream
out;
173 for (
size_t i = 0; i <
KEY_SIZE; i += 16)
193 return "-----BEGIN OpenVPN Static key V1-----";
198 return "-----END OpenVPN Static key V1-----";
std::string encode(const V &data) const
size_t decode(void *data, size_t len, const std::string &str) const
void clear()
Clears the contents of the buffer.
void init(const size_t capacity, const unsigned int flags)
Initializes the buffer with the specified capacity and flags.
void reset(const size_t min_capacity, const unsigned int flags)
Resets the buffer with the specified minimum capacity and flags.
void or_flags(const unsigned int flags)
Sets the specified flags for the buffer.
bool defined() const
Returns true if the buffer is not empty.
const T * c_data() const
Returns a const pointer to the start of the buffer.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
void set_size(const size_t size)
After an external method, operating on the array as a mutable unsigned char buffer,...
static const char * static_key_foot()
OPENVPN_SIMPLE_EXCEPTION(static_key_bad_size)
void XOR(const OpenVPNStaticKey &other)
OPENVPN_SIMPLE_EXCEPTION(static_key_parse_error)
static const char * static_key_head()
std::string render() const
unsigned char * raw_alloc()
void parse_from_file(const std::string &filename)
void parse(const std::string &key_text)
StaticKey slice(unsigned int key_specifier) const
virtual void rand_bytes(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes.
StaticKey(const unsigned char *key_data, const size_t key_size)
std::string render_hex() const
void parse_from_base64(const std::string &b64, const size_t capacity)
void init_from_rng(StrongRandomAPI &rng, const size_t key_size)
const unsigned char * data() const
std::string render_to_base64() const
StaticKey(const key_t &keydata)
Abstract base class for cryptographically strong random number generators.
Support deferred server-side state creation when client connects.
std::string render_hex_generic(const V &data, const bool caps=false)
void parse_hex(V &dest, const std::string &str)
std::string read_text(const std::string &filename, const std::uint64_t max_size=0)
std::string render_hex(const unsigned char *data, size_t size, const bool caps=false)
Implementation of the base classes for random number generators.
@ DESTRUCT_ZERO
if enabled, destructor will zero data before deletion
@ ARRAY
if enabled, use as array
static std::stringstream out