-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase64.hpp
65 lines (53 loc) · 1.56 KB
/
Base64.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef BASE64_HPP
#define BASE64_HPP
#include <cstdint>
#include <string>
#include <string_view>
namespace rrcp::common
{
class base64
{
public:
/**
* Constructor for the Base64 class.
*/
base64() = default;
/**
* Destructor for the Base64 class.
*/
~base64() = default;
/**
* Set the line break flag for encoding.
* @param lbrk If true, the encoded string will have a maximum line length of 80 characters.
*/
void set_line_break(bool lbrk) { encode_with_linebreak_ = lbrk; }
/**
* Encode binary data to base64.
* @param data The data to be encoded.
* @return The corresponding base64 encoded string.
*/
[[nodiscard]] static auto encode(std::string_view data) -> std::string;
/**
* Decode a Base64 encoded string.
* @param in The base64 encoded string.
* @return The decoded string.
*/
[[nodiscard]] static auto decode(std::string_view in) -> std::string;
private:
/**
* Check if a character is a valid Base64 character.
* @param c The character to check.
* @return True if the character is a valid Base64 character, false otherwise.
*/
[[nodiscard]] auto is_base64_char(char c) const -> bool;
/**
* Get the value of a Base64 character.
* @param c The Base64 character.
* @return The value of the character (0-63).
*/
[[nodiscard]] auto base64_char_value(char c) const -> std::uint8_t;
const std::string_view base_chars_{"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"};
bool encode_with_linebreak_{false};
};
} // namespace rrcp::common
#endif // BASE64_HPP