Path: blob/a-new-beginning/SharedDependencies/Sources/cryptopp/base64.cpp
2 views
// base64.cpp - originally written and placed in the public domain by Wei Dai12#include "pch.h"3#include "config.h"4#include "base64.h"56NAMESPACE_BEGIN(CryptoPP)7ANONYMOUS_NAMESPACE_BEGIN89const byte s_stdVec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";10const byte s_urlVec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";11const byte s_padding = '=';12const int s_stdArray[256] = {13-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,14-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,15-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,1652, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,17-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,1815, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,19-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,2041, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,21-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,22-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,23-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,24-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,25-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,26-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,27-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,28-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -129};30const int s_urlArray[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, 62, -1, -1,3452, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,35-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,3615, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,37-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,3841, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -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, -147};4849ANONYMOUS_NAMESPACE_END5051void Base64Encoder::IsolatedInitialize(const NameValuePairs ¶meters)52{53bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);54int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);5556const char *lineBreak = insertLineBreaks ? "\n" : "";5758m_filter->Initialize(CombinedNameValuePairs(59parameters,60MakeParameters(Name::EncodingLookupArray(), &s_stdVec[0], false)61(Name::PaddingByte(), s_padding)62(Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)63(Name::Separator(), ConstByteArrayParameter(lineBreak))64(Name::Terminator(), ConstByteArrayParameter(lineBreak))65(Name::Log2Base(), 6, true)));66}6768void Base64URLEncoder::IsolatedInitialize(const NameValuePairs ¶meters)69{70bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);71int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);7273const char *lineBreak = insertLineBreaks ? "\n" : "";7475m_filter->Initialize(CombinedNameValuePairs(76parameters,77MakeParameters(Name::EncodingLookupArray(), &s_urlVec[0], false)78(Name::PaddingByte(), s_padding)79(Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)80(Name::Separator(), ConstByteArrayParameter(lineBreak))81(Name::Terminator(), ConstByteArrayParameter(lineBreak))82(Name::Log2Base(), 6, true)));83}8485void Base64Decoder::IsolatedInitialize(const NameValuePairs ¶meters)86{87BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(88parameters,89MakeParameters(Name::DecodingLookupArray(), GetDecodingLookupArray(), false)(Name::Log2Base(), 6, true)));90}9192const int *Base64Decoder::GetDecodingLookupArray()93{94return s_stdArray;95}9697void Base64URLDecoder::IsolatedInitialize(const NameValuePairs ¶meters)98{99BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(100parameters,101MakeParameters(Name::DecodingLookupArray(), GetDecodingLookupArray(), false)(Name::Log2Base(), 6, true)));102}103104// Unrolled initialization, http://github.com/weidai11/cryptopp/issues/376105const int *Base64URLDecoder::GetDecodingLookupArray()106{107return s_urlArray;108}109110NAMESPACE_END111112113