27 const char* digit_set,
28 const std::vector<uint8_t>& bits_table,
29 size_t bits_per_digit,
30 size_t digits_per_group,
34 : algorithm_(algorithm),
35 digit_set_(digit_set),
36 bits_table_(bits_table),
37 bits_per_digit_(bits_per_digit),
38 digits_per_group_(digits_per_group),
41 case_sensitive_(case_sensitive),
42 max_bits_to_digit_(strlen(digit_set) - 1),
43 max_digit_to_bits_(bits_table_.size() - 1) {
50 <<
static_cast<uint16_t
>(bits) <<
" invalid for " <<
algorithm_);
60 <<
static_cast<uint16_t
>(digit) <<
" for " <<
algorithm_);
68 std::string encoded_output;
70 return (encoded_output);
85 uint8_t cur_bit_mask = 0x0;
86 auto bytes = input.begin();
90 if (bytes == input.end()) {
117 if (cur_byte & cur_bit_mask) {
146 return (encoded_output);
165 uint8_t cur_byte = 0;
166 size_t cur_bit_cnt = 0;
168 for (
const auto enc_digit : encoded_str) {
179 if (dig_bits == 0xee) {
184 if (dig_bits == 0xff) {
186 <<
algorithm_ <<
" char set" <<
": " << encoded_str);
199 dig_bits <<= shift_bits;
203 if (cur_bit_cnt < 8) {
208 output.push_back(cur_byte);
214 if (dig_bits & 0x80) {
226 if (cur_bit_cnt == 8) {
228 output.push_back(cur_byte);
229 }
else if (cur_bit_cnt && cur_byte) {
271 "abcdefghijklmnopqrstuvwxyz"
276 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff,
277 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
278 0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,62,0xff,0xff,0xff,63,
279 52,53,54,55,56,57,58,59,60,61,0xff,0xff,0xff, 0,0xff,0xff,
280 0xff, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
281 15,16,17,18,19,20,21,22,23,24,25,0xff,0xff,0xff,0xff,0xff,
282 0xff,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
283 41,42,43,44,45,46,47,48,49,50,51,0xff,0xff,0xff,0xff,0xff,
284 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
285 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
286 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
287 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
288 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
289 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
290 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
291 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
297 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff,
298 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
299 0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
300 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xff,0xff,0xff,0xff,0xff,0xff,
301 0xff,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
302 25,26,27,28,29,30,31,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
303 0xff,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
304 25,26,27,28,29,30,31,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
305 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
306 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
307 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
308 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
309 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
310 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
311 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
312 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
318 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff,
319 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
320 0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
321 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xff,0xff,0xff,0xff,0xff,0xff,
322 0xff,10,11,12,13,14,15,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
323 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
324 0xff,10,11,12,13,14,15,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
325 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
326 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
327 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
328 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
329 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
330 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
331 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
332 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
333 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
339 return (encoder.
encode(binary));
343decodeBase64 (
const std::string& encoded_str, std::vector<uint8_t>& output) {
345 encoder.
decode(encoded_str, output);
351 return (encoder.
encode(binary));
357 encoder.
decode(encoded_str, output);
363 return (encoder.
encode(binary));
367decodeHex(
const string& encoded_str, vector<uint8_t>& output) {
369 encoder.
decode(encoded_str, output);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Class for encoding and decoding binary data using Base16 (aka Hex) as described in RFC 4648.
static const char * DIGIT_SET
Set of digits used for encoding in Base16.
static const std::vector< uint8_t > BITS_TABLE
Table that maps Base16 digits to their binary data value.
Class for encoding and decoding binary data using Base32Hex as described in RFC 4648.
static const char * DIGIT_SET
Set of digits used for encoding in Base32Hex.
static const std::vector< uint8_t > BITS_TABLE
Table that maps Base32Hex digits to their binary data value.
Class for encoding and decoding binary data using Base64 as described in RFC 4648.
static const std::vector< uint8_t > BITS_TABLE
Table that maps Base64 digits to their binary data value.
static const char * DIGIT_SET
Set of digits used for encoding in Base64.
size_t max_bits_to_digit_
Maxium index value of the digit set.
const char * digit_set_
Set of digits (i.e. alphabet) used for encoding.
const char pad_char_
Character used for padding out to group size (0 means no padding)
std::string encode(const std::vector< uint8_t > &input)
Encodes binary data using the encoder's algorithm.
size_t digits_per_group_
Number of digits contained in a group.
void decode(const std::string &encoded_str, std::vector< uint8_t > &output)
Decodes an encoded string using the encoder's algorithm.
size_t max_digit_to_bits_
Maxium index value of the algorithm bit table.
std::string algorithm_
Name of the algorithm, used for logging.
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.
uint8_t digitToBits(uint8_t digit)
Translate a digit into the appropriate algorithm bit value.
size_t max_pad_
Maximum number of pad characters in a group.
std::vector< uint8_t > bits_table_
Table to translate digits to data used during decoding.
char bitsToDigit(uint8_t bits)
Translate a byte of binary data into the appropriate algorithm digit.
size_t bits_per_digit_
Number of data bits represented by a digit.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
string encodeBase64(const vector< uint8_t > &binary)
Encode binary data in the base64 format.
void decodeBase32Hex(const std::string &encoded_str, std::vector< uint8_t > &output)
Decode a base32-hex encoded string into binary data.
string encodeBase32Hex(const vector< uint8_t > &binary)
Encode binary data in the base32-hex format.
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
void decodeBase64(const std::string &encoded_str, std::vector< uint8_t > &output)
Decode a base64 encoded string into binary data.
Defines the logger used by the top-level component of kea-lfc.