Crypto++  5.6.5
Free C++ class library of cryptographic schemes
base32.cpp
1 // base32.cpp - written and placed in the public domain by Frank Palazzolo, based on hex.cpp by Wei Dai
2 
3 #include "pch.h"
4 #include "base32.h"
5 
6 NAMESPACE_BEGIN(CryptoPP)
7 
8 namespace
9 {
10  const byte s_vecUpper[] = "ABCDEFGHIJKMNPQRSTUVWXYZ23456789";
11  const byte s_vecLower[] = "abcdefghijkmnpqrstuvwxyz23456789";
12 }
13 
15 {
16  bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);
17  m_filter->Initialize(CombinedNameValuePairs(
18  parameters,
19  MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 5, true)));
20 }
21 
23 {
25  parameters,
26  MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));
27 }
28 
29 ANONYMOUS_NAMESPACE_BEGIN
30 static const int s_array[256] = {
31  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
34  -1, -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1,
35  -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,
36  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, -1, -1, -1,
37  -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,
38  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, -1, -1, -1,
39  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
45  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
47 };
48 NAMESPACE_END
49 
50 // Unrolled initialization, http://github.com/weidai11/cryptopp/issues/376
51 const int *Base32Decoder::GetDefaultDecodingLookupArray()
52 {
53  return s_array;
54 }
55 
56 NAMESPACE_END
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Definition: cryptlib.h:356
Combines two sets of NameValuePairs.
Definition: algparam.h:135
Classes for Base32Encoder and Base32Decoder.
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: basecode.cpp:115
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:502
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base32.cpp:22
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base32.cpp:14
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:285