TrinityCore
Base64.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "Base64.h"
19#include "BaseEncoding.h"
20#include "Errors.h"
21
22struct B64Impl
23{
24 static constexpr std::size_t BITS_PER_CHAR = 6;
25
26 static constexpr char PADDING = '=';
27 static constexpr char Encode(uint8 v)
28 {
29 ASSERT(v < 0x40);
30 if (v < 26) return 'A' + v;
31 if (v < 52) return 'a' + (v - 26);
32 if (v < 62) return '0' + (v - 52);
33 if (v == 62) return '+';
34 else return '/';
35 }
36
37 static constexpr uint8 DECODE_ERROR = 0xff;
38 static constexpr uint8 Decode(uint8 v)
39 {
40 if (('A' <= v) && (v <= 'Z')) return (v - 'A');
41 if (('a' <= v) && (v <= 'z')) return (v - 'a') + 26;
42 if (('0' <= v) && (v <= '9')) return (v - '0') + 52;
43 if (v == '+') return 62;
44 if (v == '/') return 63;
45 return DECODE_ERROR;
46 }
47};
48
49/*static*/ std::string Trinity::Encoding::Base64::Encode(std::vector<uint8> const& data)
50{
52}
53
55{
57}
uint8_t uint8
Definition: Define.h:144
#define ASSERT
Definition: Errors.h:68
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
static constexpr char PADDING
Definition: Base64.cpp:26
static constexpr std::size_t BITS_PER_CHAR
Definition: Base64.cpp:24
static constexpr uint8 DECODE_ERROR
Definition: Base64.cpp:37
static constexpr uint8 Decode(uint8 v)
Definition: Base64.cpp:38
static constexpr char Encode(uint8 v)
Definition: Base64.cpp:27
static Optional< std::vector< uint8 > > Decode(std::string_view data)
Definition: Base64.cpp:54
static std::string Encode(std::vector< uint8 > const &data)
Definition: Base64.cpp:49
static std::string Encode(std::vector< uint8 > const &data)
Definition: BaseEncoding.h:59
static Optional< std::vector< uint8 > > Decode(std::string_view data)
Definition: BaseEncoding.h:104