-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbase64_coder.hpp
48 lines (40 loc) · 1.27 KB
/
base64_coder.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
#pragma once
#include "fly/coders/coder.hpp"
#include <array>
#include <istream>
#include <ostream>
namespace fly::coders {
/**
* A Base64 encoder and decoder.
*
* @author Timothy Flynn ([email protected])
* @version May 3, 2020
*/
class Base64Coder : public Encoder, public Decoder
{
protected:
/**
* Base64 encode a stream.
*
* @param decoded Stream holding the contents to encode.
* @param encoded Stream to store the encoded contents.
*
* @return True if the input stream was successfully encoded.
*/
bool encode_internal(std::istream &decoded, std::ostream &encoded) override;
/**
* Base64 decode a stream.
*
* @param encoded Stream holding the contents to decode.
* @param decoded Stream to store the decoded contents.
*
* @return True if the input stream was successfully decoded.
*/
bool decode_internal(std::istream &encoded, std::ostream &decoded) override;
private:
static constexpr std::size_t const s_decoded_chunk_size = 3;
static constexpr std::size_t const s_encoded_chunk_size = 4;
std::array<std::ios::char_type, (64 * s_decoded_chunk_size) << 10> m_decoded;
std::array<std::ios::char_type, (64 * s_encoded_chunk_size) << 10> m_encoded;
};
} // namespace fly::coders