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

#include <filters.h>

Inheritance diagram for Botan::Hex_Decoder:
Botan::Filter

Public Member Functions

virtual bool attachable ()
void end_msg () override
 Hex_Decoder (Decoder_Checking checking=NONE)
std::string name () const override
virtual void start_msg ()
void write (const uint8_t input[], size_t length) override

Protected Member Functions

virtual void send (const uint8_t in[], size_t length)
void send (std::span< const uint8_t > in)
void send (std::span< const uint8_t > in, size_t length)
void send (uint8_t in)

Detailed Description

Converts hex strings to bytes

Definition at line 739 of file filters.h.

Constructor & Destructor Documentation

◆ Hex_Decoder()

Botan::Hex_Decoder::Hex_Decoder ( Decoder_Checking checking = NONE)
explicit

Construct a Hex Decoder using the specified character checking.

Parameters
checkingthe checking to use during decoding.

Definition at line 99 of file hex_filt.cpp.

99 : m_checking(c) {
100 m_in.resize(HEX_CODEC_BUFFER_SIZE);
101 m_out.resize(m_in.size() / 2);
102}
const size_t HEX_CODEC_BUFFER_SIZE
Definition hex_filt.cpp:20

References Botan::HEX_CODEC_BUFFER_SIZE.

Member Function Documentation

◆ attachable()

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::DataSink, and Botan::SecureQueue.

Definition at line 53 of file filter.h.

53{ return true; }

◆ end_msg()

void Botan::Hex_Decoder::end_msg ( )
overridevirtual

Complete the decoding and flush any buffered output

Reimplemented from Botan::Filter.

Definition at line 150 of file hex_filt.cpp.

150 {
151 size_t consumed = 0;
152 const size_t written =
153 hex_decode(m_out.data(), cast_uint8_ptr_to_char(m_in.data()), m_position, consumed, m_checking != FULL_CHECK);
154
155 send(m_out, written);
156
157 const bool not_full_bytes = consumed != m_position;
158
159 m_position = 0;
160
161 if(not_full_bytes) {
162 throw Invalid_Argument("Hex_Decoder: Input not full bytes");
163 }
164}
virtual void send(const uint8_t in[], size_t length)
Definition filter.cpp:30
@ FULL_CHECK
Definition filter.h:193
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
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:323

References Botan::cast_uint8_ptr_to_char(), Botan::FULL_CHECK, Botan::hex_decode(), and Botan::Filter::send().

◆ name()

std::string Botan::Hex_Decoder::name ( ) const
inlineoverridevirtual

Return a descriptive name for this filter

Returns
"Hex_Decoder"

Implements Botan::Filter.

Definition at line 745 of file filters.h.

745{ return "Hex_Decoder"; }

◆ send() [1/4]

void Botan::Filter::send ( const uint8_t in[],
size_t length )
protectedvirtualinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter
lengththe length of in

Definition at line 30 of file filter.cpp.

30 {
31 if(length == 0) {
32 return;
33 }
34
35 bool nothing_attached = true;
36 for(size_t j = 0; j != total_ports(); ++j) {
37 if(m_next[j] != nullptr) {
38 if(!m_write_queue.empty()) {
39 m_next[j]->write(m_write_queue.data(), m_write_queue.size());
40 }
41 m_next[j]->write(input, length);
42 nothing_attached = false;
43 }
44 }
45
46 if(nothing_attached) {
47 m_write_queue += std::make_pair(input, length);
48 } else {
49 m_write_queue.clear();
50 }
51}

Referenced by Botan::Base64_Decoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Hex_Encoder::end_msg(), operator=(), send(), Botan::Base64_Decoder::write(), Botan::Chain::write(), Botan::Fork::write(), and Botan::Hex_Decoder::write().

◆ send() [2/4]

void Botan::Filter::send ( std::span< const uint8_t > in)
inlineprotectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter

Definition at line 83 of file filter.h.

83{ send(in.data(), in.size()); }

References send().

Referenced by send().

◆ send() [3/4]

void Botan::Filter::send ( std::span< const uint8_t > in,
size_t length )
protectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter
lengththe number of bytes of in to send

This previously took a std::vector, for which the length field (allowing using just a prefix of the vector) somewhat made sense. It makes less sense now that we are using a span here; you can just use first to get a prefix.

Definition at line 22 of file filter.cpp.

22 {
23 BOTAN_ASSERT_NOMSG(length <= in.size());
24 send(in.data(), length);
25}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG, and send().

◆ send() [4/4]

void Botan::Filter::send ( uint8_t in)
inlineprotectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter

Definition at line 76 of file filter.h.

76{ send(&in, 1); }

References send().

Referenced by send().

◆ start_msg()

virtual void Botan::Filter::start_msg ( )
inlinevirtualinherited

Start a new message. Must be closed by end_msg() before another message can be started.

Definition at line 41 of file filter.h.

41{}

◆ write()

void Botan::Hex_Decoder::write ( const uint8_t input[],
size_t length )
overridevirtual

Write a portion of a message to this filter

Parameters
inputthe input as a byte array
lengththe length of the byte array input

Implements Botan::Filter.

Definition at line 117 of file hex_filt.cpp.

117 {
118 const bool ignore_ws = (m_checking != FULL_CHECK);
119
120 size_t pos = 0;
121 while(pos < length) {
122 // Drop ignored whitespace before buffering so a partial trailing nibble
123 // stays next to its pair and the fixed buffer can't fill with whitespace.
124 while(pos < length && m_position < m_in.size()) {
125 const uint8_t c = input[pos++];
126 if(ignore_ws && hex_ignorable_whitespace(c)) {
127 continue;
128 }
129 m_in[m_position++] = c;
130 }
131
132 size_t consumed = 0;
133 const size_t written =
134 hex_decode(m_out.data(), cast_uint8_ptr_to_char(m_in.data()), m_position, consumed, ignore_ws);
135
136 send(m_out, written);
137
138 if(consumed != m_position) {
139 copy_mem(m_in.data(), m_in.data() + consumed, m_position - consumed);
140 m_position = m_position - consumed;
141 } else {
142 m_position = 0;
143 }
144 }
145}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144

References Botan::cast_uint8_ptr_to_char(), Botan::copy_mem(), Botan::FULL_CHECK, Botan::hex_decode(), and Botan::Filter::send().


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