Botan 3.6.1
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:73

References Botan::hex_decode().

◆ OctetString() [2/5]

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

Create a new random OctetString

Parameters
rngis 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 93 of file symkey.h.

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

◆ OctetString() [5/5]

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

Create a new OctetString

Parameters
ina bytestring

Definition at line 99 of file symkey.h.

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

Member Function Documentation

◆ begin()

const uint8_t * Botan::OctetString::begin ( ) const
inline
Returns
start of this string

Definition at line 41 of file symkey.h.

41{ return m_data.data(); }

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

◆ bits_of()

◆ empty()

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

Definition at line 31 of file symkey.h.

31{ return m_data.empty(); }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange().

◆ end()

const uint8_t * Botan::OctetString::end ( ) const
inline
Returns
end of this string

Definition at line 46 of file symkey.h.

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

Referenced by Botan::ECIES_KA_Operation::derive_secret().

◆ length()

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

◆ 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:27
void zeroise(std::vector< T, Alloc > &vec)
Definition secmem.h:108
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:341

References begin(), length(), 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(size_t j = 0; j != m_data.size(); ++j) {
59 m_data[j] = odd_parity_of(m_data[j]);
60 }
61}

◆ size()

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

Definition at line 29 of file symkey.h.

29{ return m_data.size(); }

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

◆ to_string()

std::string Botan::OctetString::to_string ( ) const
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:35

References Botan::hex_encode().


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