Kea 2.7.6
|
Class for encoding and decoding binary data using an algorithm described in RFC 4648. More...
#include <encode.h>
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) | |
Class for encoding and decoding binary data using an algorithm described in RFC 4648.
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.
algorithm | name of the algorithm, used for logging |
digit_set | set of digits (i.e. alphabet) used for encoding |
bits_table | table to translate digits to data used during decoding |
bits_per_digit | number of data bits represented by a digit |
digits_per_group | number of digits contained in a group |
pad_char | character used for padding out to group size (0 means no padding) |
max_pad | maximum number of pad characters in a group |
case_sensitive | indicates if the algorithm's digit set is case sensitive |
|
virtualdefault |
char isc::util::encode::BaseNEncoder::bitsToDigit | ( | uint8_t | bits | ) |
Translate a byte of binary data into the appropriate algorithm digit.
bits | binary value to translate |
BadValue | if 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().
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.
encoded_str | encoded string to decode | |
[out] | output | vector into which the decoded data is stored |
BadValue | if 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().
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.
digit | the algorithm digit to translate |
Definition at line 57 of file encode.cc.
References algorithm_, bits_table_, isc_throw, and max_digit_to_bits_.
Referenced by decode().
std::string isc::util::encode::BaseNEncoder::encode | ( | const std::vector< uint8_t > & | input | ) |
Encodes binary data using the encoder's algorithm.
input | binary data to encode |
BadValue | if 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().
|
inline |
Get the algorithm name.
Definition at line 85 of file encode.h.
References algorithm_.
|
inline |
Get the number of data bits represented by a digit.
Definition at line 106 of file encode.h.
References bits_per_digit_.
|
inline |
Get the digit lookup table.
Definition at line 99 of file encode.h.
References bits_table_.
|
inline |
Get the digit set.
Definition at line 92 of file encode.h.
References digit_set_.
|
inline |
Get the number of digits contained in a group.
Definition at line 113 of file encode.h.
References digits_per_group_.
|
inline |
Get the maximum index value of the digit set.
Definition at line 134 of file encode.h.
References max_bits_to_digit_.
|
inline |
Get the maximum index value of the algorithm bit table.
Definition at line 141 of file encode.h.
References max_digit_to_bits_.
|
inline |
|
inline |
|
inline |
Indicates whether or not the algorithm's digit set is case-sensitive.
Definition at line 149 of file encode.h.
References case_sensitive_.
|
protected |
Name of the algorithm, used for logging.
Definition at line 155 of file encode.h.
Referenced by bitsToDigit(), decode(), digitToBits(), and getAlgorithm().
|
protected |
Number of data bits represented by a digit.
Definition at line 168 of file encode.h.
Referenced by decode(), encode(), and getBitsPerDigit().
|
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().
|
protected |
Indicates whether or not the algorithm's digit set is case-sensitive.
Definition at line 180 of file encode.h.
Referenced by isCaseSensitive().
|
protected |
Set of digits (i.e. alphabet) used for encoding.
Definition at line 158 of file encode.h.
Referenced by bitsToDigit(), and getDigitSet().
|
protected |
Number of digits contained in a group.
Definition at line 171 of file encode.h.
Referenced by decode(), encode(), and getDigitsPerGroup().
|
protected |
Maximum index value of the digit set.
Definition at line 183 of file encode.h.
Referenced by bitsToDigit(), and getMaxBitsToDigit().
|
protected |
Maximum index value of the algorithm bit table.
Definition at line 186 of file encode.h.
Referenced by digitToBits(), and getMaxDigitToBits().
|
protected |
Maximum number of pad characters in a group.
Definition at line 177 of file encode.h.
Referenced by decode(), and getMaxPad().
|
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().