Fabcoin Core  0.16.2
P2P Digital Currency
base64.cpp
Go to the documentation of this file.
1 // base64.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 #include "base64.h"
5 
7 
8 namespace
9 {
10  const byte s_stdVec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
11  const byte s_urlVec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
12  const byte s_padding = '=';
13 }
14 
16 {
17  bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);
18  int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);
19 
20  const char *lineBreak = insertLineBreaks ? "\n" : "";
21 
23  parameters,
24  MakeParameters(Name::EncodingLookupArray(), &s_stdVec[0], false)
25  (Name::PaddingByte(), s_padding)
26  (Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)
27  (Name::Separator(), ConstByteArrayParameter(lineBreak))
28  (Name::Terminator(), ConstByteArrayParameter(lineBreak))
29  (Name::Log2Base(), 6, true)));
30 }
31 
33 {
34  bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);
35  int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);
36 
37  const char *lineBreak = insertLineBreaks ? "\n" : "";
38 
40  parameters,
41  MakeParameters(Name::EncodingLookupArray(), &s_urlVec[0], false)
42  (Name::PaddingByte(), s_padding)
43  (Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)
44  (Name::Separator(), ConstByteArrayParameter(lineBreak))
45  (Name::Terminator(), ConstByteArrayParameter(lineBreak))
46  (Name::Log2Base(), 6, true)));
47 }
48 
50 {
52  parameters,
53  MakeParameters(Name::DecodingLookupArray(), GetDecodingLookupArray(), false)(Name::Log2Base(), 6, true)));
54 }
55 
57 {
58  static volatile bool s_initialized = false;
59  static int s_array[256];
60 
61  if (!s_initialized)
62  {
63  InitializeDecodingLookupArray(s_array, s_stdVec, 64, false);
64  s_initialized = true;
65  }
66  return s_array;
67 }
68 
70 {
72  parameters,
73  MakeParameters(Name::DecodingLookupArray(), GetDecodingLookupArray(), false)(Name::Log2Base(), 6, true)));
74 }
75 
77 {
78  static volatile bool s_initialized = false;
79  static int s_array[256];
80 
81  if (!s_initialized)
82  {
83  InitializeDecodingLookupArray(s_array, s_urlVec, 64, false);
84  s_initialized = true;
85  }
86  return s_array;
87 }
88 
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:29
uint8_t byte
Definition: Common.h:57
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base64.cpp:69
member_ptr< BufferedTransformation > m_filter
Definition: filters.h:972
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Definition: cryptlib.h:350
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Combines two sets of NameValuePairs.
Definition: algparam.h:135
static const int *CRYPTOPP_API GetDecodingLookupArray()
Provides the default decoding lookup table.
Definition: base64.cpp:76
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: basecode.cpp:115
static const int *CRYPTOPP_API GetDecodingLookupArray()
Provides the default decoding lookup table.
Definition: base64.cpp:56
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:498
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:382
Classes for the Base64Encoder, Base64Decoder, Base64URLEncoder and Base64URLDecoder.
void IsolatedInitialize(const NameValuePairs &parameters)
Definition: base64.cpp:32
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base64.cpp:49
virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Definition: cryptlib.cpp:435
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base64.cpp:15
Interface for retrieving values given their names.
Definition: cryptlib.h:279