Kea 2.7.6
isc::util::encode::BaseNEncoder Class Reference

Class for encoding and decoding binary data using an algorithm described in RFC 4648. More...

#include <encode.h>

+ Inheritance diagram for isc::util::encode::BaseNEncoder:

Public Member Functions

 BaseNEncoder (const std::string &algorithm, const char *digit_set, const std::vector< uint8_t > &bits_table, size_t bits_per_digit, size_t digits_per_group, const char pad_char, size_t max_pad, bool case_sensitive)
 Constructor.
 
virtual ~BaseNEncoder ()=default
 Destructor.
 
char bitsToDigit (uint8_t bits)
 Translate a byte of binary data into the appropriate algorithm digit.
 
void decode (const std::string &encoded_str, std::vector< uint8_t > &output)
 Decodes an encoded string using the encoder's algorithm.
 
uint8_t digitToBits (uint8_t digit)
 Translate a digit into the appropriate algorithm bit value.
 
std::string encode (const std::vector< uint8_t > &input)
 Encodes binary data using the encoder's algorithm.
 
std::string getAlgorithm () const
 Get the algorithm name.
 
size_t getBitsPerDigit ()
 Get the number of data bits represented by a digit.
 
const std::vector< uint8_t > & getBitsTable () const
 Get the digit lookup table.
 
const char * getDigitSet () const
 Get the digit set.
 
size_t getDigitsPerGroup () const
 Get the number of digits contained in a group.
 
size_t getMaxBitsToDigit ()
 Get the maximum index value of the digit set.
 
size_t getMaxDigitToBits ()
 Get the maximum index value of the algorithm bit table.
 
size_t getMaxPad ()
 Get the maximum number of pad characters in a group.
 
uint8_t getPadChar () const
 Get the character used for padding out to group size (0 means no padding)
 
bool isCaseSensitive ()
 Indicates whether or not the algorithm's digit set is case-sensitive.
 

Protected Attributes

std::string algorithm_
 Name of the algorithm, used for logging.
 
size_t bits_per_digit_
 Number of data bits represented by a digit.
 
std::vector< uint8_t > bits_table_
 Table to translate digits to data used during decoding.
 
bool case_sensitive_
 Indicates whether or not the algorithm's digit set is case-sensitive.
 
const char * digit_set_
 Set of digits (i.e. alphabet) used for encoding.
 
size_t digits_per_group_
 Number of digits contained in a group.
 
size_t max_bits_to_digit_
 Maximum index value of the digit set.
 
size_t max_digit_to_bits_
 Maximum index value of the algorithm bit table.
 
size_t max_pad_
 Maximum number of pad characters in a group.
 
const char pad_char_
 Character used for padding out to group size (0 means no padding)
 

Detailed Description

Class for encoding and decoding binary data using an algorithm described in RFC 4648.

Definition at line 20 of file encode.h.

Constructor & Destructor Documentation

◆ BaseNEncoder()

isc::util::encode::BaseNEncoder::BaseNEncoder ( const std::string & algorithm,
const char * digit_set,
const std::vector< uint8_t > & bits_table,
size_t bits_per_digit,
size_t digits_per_group,
const char pad_char,
size_t max_pad,
bool case_sensitive )

Constructor.

Parameters
algorithmname of the algorithm, used for logging
digit_setset of digits (i.e. alphabet) used for encoding
bits_tabletable to translate digits to data used during decoding
bits_per_digitnumber of data bits represented by a digit
digits_per_groupnumber of digits contained in a group
pad_charcharacter used for padding out to group size (0 means no padding)
max_padmaximum number of pad characters in a group
case_sensitiveindicates if the algorithm's digit set is case sensitive

Definition at line 26 of file encode.cc.

◆ ~BaseNEncoder()

virtual isc::util::encode::BaseNEncoder::~BaseNEncoder ( )
virtualdefault

Destructor.

References encode().

+ Here is the call graph for this function:

Member Function Documentation

◆ bitsToDigit()

char isc::util::encode::BaseNEncoder::bitsToDigit ( uint8_t bits)

Translate a byte of binary data into the appropriate algorithm digit.

Parameters
bitsbinary value to translate
Returns
char containing the digit corresponding to the binary value
Exceptions
BadValueif the bits value is out of range

Definition at line 47 of file encode.cc.

References algorithm_, digit_set_, isc_throw, and max_bits_to_digit_.

Referenced by encode().

◆ decode()

void isc::util::encode::BaseNEncoder::decode ( const std::string & encoded_str,
std::vector< uint8_t > & output )

Decodes an encoded string using the encoder's algorithm.

Parameters
encoded_strencoded string to decode
[out]outputvector into which the decoded data is stored
Exceptions
BadValueif an error occurs during decoding

Definition at line 150 of file encode.cc.

References algorithm_, bits_per_digit_, digits_per_group_, digitToBits(), isc_throw, max_pad_, and pad_char_.

Referenced by isc::util::encode::decodeBase32Hex(), isc::util::encode::decodeBase64(), and isc::util::encode::decodeHex().

+ Here is the call graph for this function:

◆ digitToBits()

uint8_t isc::util::encode::BaseNEncoder::digitToBits ( uint8_t digit)

Translate a digit into the appropriate algorithm bit value.

Function maps all 256 ASCII chars to their corresponding algorithm-specific data value. A data value of 0xee marks a char as whitespace, 0xff marks a char is invalid.

Parameters
digitthe algorithm digit to translate
Returns
byte containing the binary value corresponding to the digit

Definition at line 57 of file encode.cc.

References algorithm_, bits_table_, isc_throw, and max_digit_to_bits_.

Referenced by decode().

◆ encode()

std::string isc::util::encode::BaseNEncoder::encode ( const std::vector< uint8_t > & input)

Encodes binary data using the encoder's algorithm.

Parameters
inputbinary data to encode
Returns
resultant encoded data string
Exceptions
BadValueif an error occurs during encoding

Definition at line 67 of file encode.cc.

References bits_per_digit_, bitsToDigit(), digits_per_group_, and pad_char_.

Referenced by ~BaseNEncoder(), isc::util::encode::encodeBase32Hex(), isc::util::encode::encodeBase64(), and isc::util::encode::encodeHex().

+ Here is the call graph for this function:

◆ getAlgorithm()

std::string isc::util::encode::BaseNEncoder::getAlgorithm ( ) const
inline

Get the algorithm name.

Returns
string containing the algorithm name

Definition at line 85 of file encode.h.

References algorithm_.

◆ getBitsPerDigit()

size_t isc::util::encode::BaseNEncoder::getBitsPerDigit ( )
inline

Get the number of data bits represented by a digit.

Returns
number of data bits per digit

Definition at line 106 of file encode.h.

References bits_per_digit_.

◆ getBitsTable()

const std::vector< uint8_t > & isc::util::encode::BaseNEncoder::getBitsTable ( ) const
inline

Get the digit lookup table.

Returns
vector containing the lookup table

Definition at line 99 of file encode.h.

References bits_table_.

◆ getDigitSet()

const char * isc::util::encode::BaseNEncoder::getDigitSet ( ) const
inline

Get the digit set.

Returns
string containing the set of digits

Definition at line 92 of file encode.h.

References digit_set_.

◆ getDigitsPerGroup()

size_t isc::util::encode::BaseNEncoder::getDigitsPerGroup ( ) const
inline

Get the number of digits contained in a group.

Returns
number of digits per group

Definition at line 113 of file encode.h.

References digits_per_group_.

◆ getMaxBitsToDigit()

size_t isc::util::encode::BaseNEncoder::getMaxBitsToDigit ( )
inline

Get the maximum index value of the digit set.

Returns
Maximum index value of the digit set

Definition at line 134 of file encode.h.

References max_bits_to_digit_.

◆ getMaxDigitToBits()

size_t isc::util::encode::BaseNEncoder::getMaxDigitToBits ( )
inline

Get the maximum index value of the algorithm bit table.

Returns
Maximum index value of the algorithm bit table

Definition at line 141 of file encode.h.

References max_digit_to_bits_.

◆ getMaxPad()

size_t isc::util::encode::BaseNEncoder::getMaxPad ( )
inline

Get the maximum number of pad characters in a group.

Returns
Maximum number of pad characters

Definition at line 127 of file encode.h.

References max_pad_.

◆ getPadChar()

uint8_t isc::util::encode::BaseNEncoder::getPadChar ( ) const
inline

Get the character used for padding out to group size (0 means no padding)

Returns
Character used as a pad byte

Definition at line 120 of file encode.h.

References pad_char_.

◆ isCaseSensitive()

bool isc::util::encode::BaseNEncoder::isCaseSensitive ( )
inline

Indicates whether or not the algorithm's digit set is case-sensitive.

Returns
true if the digit set is case-sensitive, false otherwise

Definition at line 149 of file encode.h.

References case_sensitive_.

Member Data Documentation

◆ algorithm_

std::string isc::util::encode::BaseNEncoder::algorithm_
protected

Name of the algorithm, used for logging.

Definition at line 155 of file encode.h.

Referenced by bitsToDigit(), decode(), digitToBits(), and getAlgorithm().

◆ bits_per_digit_

size_t isc::util::encode::BaseNEncoder::bits_per_digit_
protected

Number of data bits represented by a digit.

Definition at line 168 of file encode.h.

Referenced by decode(), encode(), and getBitsPerDigit().

◆ bits_table_

std::vector<uint8_t> isc::util::encode::BaseNEncoder::bits_table_
protected

Table to translate digits to data used during decoding.

The table must map all 256 ASCII chars to their corresponding algorithm-specific data value. A data value of 0xee marks a char as whitespace, 0xff marks a char is invalid

Definition at line 165 of file encode.h.

Referenced by digitToBits(), and getBitsTable().

◆ case_sensitive_

bool isc::util::encode::BaseNEncoder::case_sensitive_
protected

Indicates whether or not the algorithm's digit set is case-sensitive.

Definition at line 180 of file encode.h.

Referenced by isCaseSensitive().

◆ digit_set_

const char* isc::util::encode::BaseNEncoder::digit_set_
protected

Set of digits (i.e. alphabet) used for encoding.

Definition at line 158 of file encode.h.

Referenced by bitsToDigit(), and getDigitSet().

◆ digits_per_group_

size_t isc::util::encode::BaseNEncoder::digits_per_group_
protected

Number of digits contained in a group.

Definition at line 171 of file encode.h.

Referenced by decode(), encode(), and getDigitsPerGroup().

◆ max_bits_to_digit_

size_t isc::util::encode::BaseNEncoder::max_bits_to_digit_
protected

Maximum index value of the digit set.

Definition at line 183 of file encode.h.

Referenced by bitsToDigit(), and getMaxBitsToDigit().

◆ max_digit_to_bits_

size_t isc::util::encode::BaseNEncoder::max_digit_to_bits_
protected

Maximum index value of the algorithm bit table.

Definition at line 186 of file encode.h.

Referenced by digitToBits(), and getMaxDigitToBits().

◆ max_pad_

size_t isc::util::encode::BaseNEncoder::max_pad_
protected

Maximum number of pad characters in a group.

Definition at line 177 of file encode.h.

Referenced by decode(), and getMaxPad().

◆ pad_char_

const char isc::util::encode::BaseNEncoder::pad_char_
protected

Character used for padding out to group size (0 means no padding)

Definition at line 174 of file encode.h.

Referenced by decode(), encode(), and getPadChar().


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