forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase64.h
47 lines (38 loc) · 1.42 KB
/
base64.h
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
#include <QByteArray>
namespace Qt515Base64 {
enum Base64Option {
Base64Encoding = 0,
Base64UrlEncoding = 1,
KeepTrailingEquals = 0,
OmitTrailingEquals = 2,
IgnoreBase64DecodingErrors = 0,
AbortOnBase64DecodingErrors = 4,
};
Q_DECLARE_FLAGS(Base64Options, Base64Option)
Q_DECLARE_OPERATORS_FOR_FLAGS(Base64Options)
enum class Base64DecodingStatus {
Ok,
IllegalInputLength,
IllegalCharacter,
IllegalPadding,
};
class FromBase64Result {
public:
QByteArray decoded;
Base64DecodingStatus decodingStatus;
void swap(FromBase64Result &other) noexcept {
qSwap(decoded, other.decoded);
qSwap(decodingStatus, other.decodingStatus);
}
explicit operator bool() const noexcept { return decodingStatus == Base64DecodingStatus::Ok; }
#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC)
QByteArray &operator*() &noexcept { return decoded; }
const QByteArray &operator*() const &noexcept { return decoded; }
QByteArray &&operator*() &&noexcept { return std::move(decoded); }
#else
QByteArray &operator*() noexcept { return decoded; }
const QByteArray &operator*() const noexcept { return decoded; }
#endif
};
FromBase64Result QByteArray_fromBase64Encoding(const QByteArray &base64, Base64Options options);
} // namespace Qt515Base64