TrinityCore
Base32.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 "Base32.h"
19#include "BaseEncoding.h"
20#include "Errors.h"
21
22struct B32Impl
23{
24 static constexpr std::size_t BITS_PER_CHAR = 5;
25
26 static constexpr char PADDING = '=';
27 static constexpr char Encode(uint8 v)
28 {
29 ASSERT(v < 0x20);
30 if (v < 26) return 'A'+v;
31 else return '2' + (v-26);
32 }
33
34 static constexpr uint8 DECODE_ERROR = 0xff;
35 static constexpr uint8 Decode(uint8 v)
36 {
37 if (v == '0') return Decode('O');
38 if (v == '1') return Decode('l');
39 if (v == '8') return Decode('B');
40 if (('A' <= v) && (v <= 'Z')) return (v-'A');
41 if (('a' <= v) && (v <= 'z')) return (v-'a');
42 if (('2' <= v) && (v <= '7')) return (v-'2')+26;
43 return DECODE_ERROR;
44 }
45};
46
47/*static*/ std::string Trinity::Encoding::Base32::Encode(std::vector<uint8> const& data)
48{
50}
51
53{
55}
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 std::size_t BITS_PER_CHAR
Definition: Base32.cpp:24
static constexpr char Encode(uint8 v)
Definition: Base32.cpp:27
static constexpr uint8 Decode(uint8 v)
Definition: Base32.cpp:35
static constexpr uint8 DECODE_ERROR
Definition: Base32.cpp:34
static constexpr char PADDING
Definition: Base32.cpp:26
static Optional< std::vector< uint8 > > Decode(std::string_view data)
Definition: Base32.cpp:52
static std::string Encode(std::vector< uint8 > const &data)
Definition: Base32.cpp:47
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