Botan 3.13.0
Crypto and TLS for C&
Botan::OctetString Class Referencefinal

#include <symkey.h>

Public Member Functions

const uint8_t * begin () const
secure_vector< uint8_t > bits_of () const
bool empty () const
const uint8_t * end () const
size_t length () const
 OctetString (const uint8_t in[], size_t len)
 OctetString (RandomNumberGenerator &rng, size_t len)
 OctetString (secure_vector< uint8_t > in)
 OctetString (std::span< const uint8_t > in)
 OctetString (std::string_view str="")
OctetStringoperator^= (const OctetString &other)
void set_odd_parity ()
size_t size () const
std::string to_string () const

Detailed Description

Octet String

Definition at line 22 of file symkey.h.

Constructor & Destructor Documentation

◆ OctetString() [1/5]

Botan::OctetString::OctetString ( std::string_view str = "")
explicit

Create a new OctetString

Parameters
stris a hex encoded string

Definition at line 27 of file symkey.cpp.

27 {
28 if(!hex_string.empty()) {
29 m_data.resize(1 + hex_string.length() / 2);
30 m_data.resize(hex_decode(m_data.data(), hex_string));
31 }
32}
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition hex.cpp:75

References Botan::hex_decode().

Referenced by OctetString(), and operator^=().

◆ OctetString() [2/5]

Botan::OctetString::OctetString ( RandomNumberGenerator & rng,
size_t len )

Create a new random OctetString

Parameters
Random Number Generatorsis a random number generator
lenis the desired length in bytes

Definition at line 20 of file symkey.cpp.

20 {
21 rng.random_vec(m_data, len);
22}

References Botan::RandomNumberGenerator::random_vec().

◆ OctetString() [3/5]

Botan::OctetString::OctetString ( const uint8_t in[],
size_t len )

Create a new OctetString

Parameters
inis an array
lenis the length of in in bytes

Definition at line 37 of file symkey.cpp.

37 {
38 m_data.assign(in, in + n);
39}

◆ OctetString() [4/5]

Botan::OctetString::OctetString ( std::span< const uint8_t > in)
inlineexplicit

Create a new OctetString

Parameters
ina bytestring

Definition at line 106 of file symkey.h.

106: m_data(in.begin(), in.end()) {}

References begin(), end(), and OctetString().

◆ OctetString() [5/5]

Botan::OctetString::OctetString ( secure_vector< uint8_t > in)
inlineexplicit

Create a new OctetString

Parameters
ina bytestring

Definition at line 112 of file symkey.h.

112: m_data(std::move(in)) {}

Member Function Documentation

◆ begin()

const uint8_t * Botan::OctetString::begin ( ) const
inline

Return a pointer to the first byte

Returns
start of this string

Definition at line 52 of file symkey.h.

52{ return m_data.data(); }

Referenced by Botan::ECIES_KA_Operation::derive_secret(), end(), OctetString(), Botan::operator^(), operator^=(), and Botan::SymmetricAlgorithm::set_key().

◆ bits_of()

◆ empty()

bool Botan::OctetString::empty ( ) const
inline

Test whether this octet string is empty

Returns
true if this string holds no bytes

Definition at line 40 of file symkey.h.

40{ return m_data.empty(); }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::get_cipher(), and Botan::Keyed_Filter::set_iv().

◆ end()

const uint8_t * Botan::OctetString::end ( ) const
inline

Return a pointer one past the last byte

Returns
end of this string

Definition at line 58 of file symkey.h.

58{ return begin() + m_data.size(); }
const uint8_t * begin() const
Definition symkey.h:52

References begin().

Referenced by Botan::ECIES_KA_Operation::derive_secret(), and OctetString().

◆ length()

size_t Botan::OctetString::length ( ) const
inline

Return the length of this octet string

Returns
size of this octet string in bytes

Definition at line 28 of file symkey.h.

28{ return m_data.size(); }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::operator^(), operator^=(), Botan::Keyed_Filter::set_iv(), and Botan::SymmetricAlgorithm::set_key().

◆ operator^=()

OctetString & Botan::OctetString::operator^= ( const OctetString & other)

XOR the contents of another octet string into this one

Parameters
otheroctet string
Returns
reference to this

Definition at line 73 of file symkey.cpp.

73 {
74 if(&k == this) {
75 zeroise(m_data);
76 return (*this);
77 }
78 xor_buf(m_data.data(), k.begin(), std::min(length(), k.length()));
79 return (*this);
80}
size_t length() const
Definition symkey.h:28
void zeroise(std::vector< T, Alloc > &vec)
Definition secmem.h:241
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:403

References begin(), length(), OctetString(), Botan::xor_buf(), and Botan::zeroise().

◆ set_odd_parity()

void Botan::OctetString::set_odd_parity ( )

Force to have odd parity

Deprecated. There is no reason to use this outside of interacting with some very old or weird system which requires DES and also which do not automatically ignore the parity bits.

Definition at line 57 of file symkey.cpp.

57 {
58 for(auto& b : m_data) {
59 b = odd_parity_of(b);
60 }
61}

◆ size()

size_t Botan::OctetString::size ( ) const
inline

Return the length of this octet string

Returns
size of this octet string in bytes

Definition at line 34 of file symkey.h.

34{ return m_data.size(); }

Referenced by Botan::rfc3394_keyunwrap(), and Botan::rfc3394_keywrap().

◆ to_string()

std::string Botan::OctetString::to_string ( ) const

Format this octet string as a hex string

Returns
this encoded as hex

Definition at line 66 of file symkey.cpp.

66 {
67 return hex_encode(m_data.data(), m_data.size());
68}
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:34

References Botan::hex_encode().


The documentation for this class was generated from the following files: