Webdar 1.0.0
Web user interface to libdar
base64.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef BASE64_HPP
25#define BASE64_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <string>
36
37 // webdar headers
38#include "exceptions.hpp"
39
41
42class base64
43{
44public:
45 base64() {};
46 base64(const base64 & ref) = default;
47 base64(base64 && ref) noexcept = default;
48 base64 & operator = (const base64 & ref) = default;
49 base64 & operator = (base64 && ref) noexcept = default;
50 ~base64() = default;
51
52 std::string decode(const std::string & str) const;
53 std::string encode(const std::string & str) const;
54
55 typedef char decoded_block[3];
56 typedef char encoded_block[4];
57
58 void small_decode(const encoded_block & b64, decoded_block & out) const;
59 void small_encode(unsigned int num_bytes, const decoded_block & bin, encoded_block & out) const;
60
61private:
62 static std::string convert(char a, char b, char c, char d);
63 static std::string unconvert(int num_char,
64 unsigned char a,
65 unsigned char b,
66 unsigned char c);
67 static unsigned int value64(char a);
68 static char to_value64(unsigned int val);
69 static void complement(std::string & ref);
70};
71
72#endif
implements the encoding to and decoding from base64
Definition: base64.hpp:43