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);