2002-10-04 17:31:41 +00:00
|
|
|
// base64.cpp - written and placed in the public domain by Wei Dai
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "base64.h"
|
|
|
|
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
2015-07-02 01:06:29 +00:00
|
|
|
|
|
|
|
// Base64
|
|
|
|
static const byte s_vec1[] =
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
// Base64URL
|
|
|
|
static const byte s_vec2[] =
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
2002-10-04 17:31:41 +00:00
|
|
|
static const byte s_padding = '=';
|
|
|
|
|
|
|
|
void Base64Encoder::IsolatedInitialize(const NameValuePairs ¶meters)
|
|
|
|
{
|
2003-07-18 04:35:30 +00:00
|
|
|
bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);
|
|
|
|
int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);
|
2003-03-21 18:10:58 +00:00
|
|
|
|
|
|
|
const char *lineBreak = insertLineBreaks ? "\n" : "";
|
2002-10-04 17:31:41 +00:00
|
|
|
|
|
|
|
m_filter->Initialize(CombinedNameValuePairs(
|
|
|
|
parameters,
|
2015-07-02 01:06:29 +00:00
|
|
|
MakeParameters(Name::EncodingLookupArray(), &s_vec1[0], false)
|
|
|
|
(Name::PaddingByte(), s_padding)
|
|
|
|
(Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)
|
|
|
|
(Name::Separator(), ConstByteArrayParameter(lineBreak))
|
|
|
|
(Name::Terminator(), ConstByteArrayParameter(lineBreak))
|
|
|
|
(Name::Log2Base(), 6, true)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Base64URLEncoder::IsolatedInitialize(const NameValuePairs ¶meters)
|
|
|
|
{
|
|
|
|
bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);
|
|
|
|
int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);
|
|
|
|
|
|
|
|
const char *lineBreak = insertLineBreaks ? "\n" : "";
|
|
|
|
|
|
|
|
m_filter->Initialize(CombinedNameValuePairs(
|
|
|
|
parameters,
|
|
|
|
MakeParameters(Name::EncodingLookupArray(), &s_vec2[0], false)
|
2003-07-18 04:35:30 +00:00
|
|
|
(Name::PaddingByte(), s_padding)
|
|
|
|
(Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)
|
|
|
|
(Name::Separator(), ConstByteArrayParameter(lineBreak))
|
|
|
|
(Name::Terminator(), ConstByteArrayParameter(lineBreak))
|
|
|
|
(Name::Log2Base(), 6, true)));
|
2002-10-04 17:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int *Base64Decoder::GetDecodingLookupArray()
|
|
|
|
{
|
2010-06-18 00:51:12 +00:00
|
|
|
static volatile bool s_initialized = false;
|
2002-10-04 17:31:41 +00:00
|
|
|
static int s_array[256];
|
2015-07-02 01:06:29 +00:00
|
|
|
|
|
|
|
if (!s_initialized)
|
|
|
|
{
|
|
|
|
InitializeDecodingLookupArray(s_array, s_vec1, 64, false);
|
|
|
|
s_initialized = true;
|
|
|
|
}
|
|
|
|
return s_array;
|
|
|
|
}
|
2002-10-04 17:31:41 +00:00
|
|
|
|
2015-07-02 01:06:29 +00:00
|
|
|
const int *Base64URLDecoder::GetDecodingLookupArray()
|
|
|
|
{
|
|
|
|
static volatile bool s_initialized = false;
|
|
|
|
static int s_array[256];
|
|
|
|
|
2002-10-04 17:31:41 +00:00
|
|
|
if (!s_initialized)
|
|
|
|
{
|
2015-07-02 01:06:29 +00:00
|
|
|
InitializeDecodingLookupArray(s_array, s_vec2, 64, false);
|
2002-10-04 17:31:41 +00:00
|
|
|
s_initialized = true;
|
|
|
|
}
|
|
|
|
return s_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
NAMESPACE_END
|