Crypto++  5.6.3
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 static const byte s_vecUpper[] = "ABCDEFGHIJKMNPQRSTUVWXYZ23456789";
9 static const byte s_vecLower[] = "abcdefghijkmnpqrstuvwxyz23456789";
10 
11 void Base32Encoder::IsolatedInitialize(const NameValuePairs &parameters)
12 {
13  bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);
15  parameters,
16  MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 5, true)));
17 }
18 
20 {
22  parameters,
23  MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));
24 }
25 
26 const int *Base32Decoder::GetDefaultDecodingLookupArray()
27 {
28  static volatile bool s_initialized = false;
29  static int s_array[256];
30 
31  if (!s_initialized)
32  {
33  InitializeDecodingLookupArray(s_array, s_vecUpper, 32, true);
34  s_initialized = true;
35  }
36  return s_array;
37 }
38 
39 NAMESPACE_END
Base32 encodes data.
Definition: base32.h:17
Combines two sets of NameValuePairs.
Definition: algparam.h:135
Classes for Base32Encoder and Base32Decoder.
static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive)
Intializes BaseN lookup array.
Definition: basecode.cpp:178
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:554
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base32.cpp:19
void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Definition: filters.cpp:71
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:277