-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64.h
More file actions
131 lines (102 loc) · 4.84 KB
/
base64.h
File metadata and controls
131 lines (102 loc) · 4.84 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once
#include "impl/encode.h"
#include "impl/decode.h"
namespace base64
{
////////////////////////////////////////////////////////////////////////////////////////////////
// encode functions declaration
////////////////////////////////////////////////////////////////////////////////////////////////
size_t calc_encoded_size(size_t raw_size) noexcept;
size_t calc_encoded_size_url(size_t raw_size) noexcept;
template <typename raw_array, typename base64_array>
error_code_t encode(
const raw_array & raw_data,
base64_array & base64_data);
template <typename raw_array, typename base64_array>
error_code_t encode_url(
const raw_array & raw_data,
base64_array & base64_data);
////////////////////////////////////////////////////////////////////////////////////////////////
// decode functions declaration
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename base64_array>
size_t calc_decoded_size(const base64_array & base64_data) noexcept;
template <typename base64_array>
size_t calc_decoded_size_url(const base64_array & base64_data) noexcept;
template <typename base64_array, typename raw_array>
error_code_t decode(
const base64_array & base64_data,
raw_array & raw_data);
template <typename base64_array, typename raw_array>
error_code_t decode_url(
const base64_array & base64_data,
raw_array & raw_data);
////////////////////////////////////////////////////////////////////////////////////////////////
// encode functions (definition)
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
inline size_t calc_encoded_size(size_t raw_size) noexcept
{
return calc_encoded_size_impl<def_encoding_t>(raw_size);
}
////////////////////////////////////////////////////////////////////////////////////////////////
inline size_t calc_encoded_size_url(size_t raw_size) noexcept
{
return calc_encoded_size_impl<url_encoding_t>(raw_size);
}
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename raw_array, typename base64_array>
inline error_code_t encode(
const raw_array & raw_data,
base64_array & base64_data )
{
return encode_impl<def_encoding_t>(
make_const_adapter(raw_data),
make_mutable_adapter(base64_data));
}
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename raw_array, typename base64_array>
inline error_code_t encode_url(
const raw_array & raw_data,
base64_array & base64_data )
{
return encode_impl<url_encoding_t>(
make_const_adapter(raw_data),
make_mutable_adapter(base64_data));
}
////////////////////////////////////////////////////////////////////////////////////////////////
// decode functions definition
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename base64_array>
inline size_t calc_decoded_size(const base64_array & base64_data) noexcept
{
return calc_decoded_size_impl<def_encoding_t>(make_const_adapter(base64_data));
}
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename base64_array>
inline size_t calc_decoded_size_url(const base64_array & base64_data) noexcept
{
return calc_decoded_size_impl<url_encoding_t>(make_const_adapter(base64_data));
}
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename base64_array, typename raw_array>
inline error_code_t decode(
const base64_array & base64_data,
raw_array & raw_data)
{
return decode_impl<def_encoding_t>(
make_const_adapter(base64_data),
make_mutable_adapter(raw_data));
}
////////////////////////////////////////////////////////////////////////////////////////////////
template <typename base64_array, typename raw_array>
inline error_code_t decode_url(
const base64_array & base64_data,
raw_array & raw_data)
{
return decode_impl<url_encoding_t>(
make_const_adapter(base64_data),
make_mutable_adapter(raw_data));
}
} // namespace base64