Path: blob/a-new-beginning/SharedDependencies/Sources/cryptopp/base32.cpp
2 views
// base32.cpp - written and placed in the public domain by Frank Palazzolo, based on hex.cpp by Wei Dai1// extended hex alphabet added by JW in November, 2017.23#include "pch.h"4#include "base32.h"56NAMESPACE_BEGIN(CryptoPP)7ANONYMOUS_NAMESPACE_BEGIN89const byte s_stdUpper[] = "ABCDEFGHIJKMNPQRSTUVWXYZ23456789";10const byte s_stdLower[] = "abcdefghijkmnpqrstuvwxyz23456789";11const byte s_hexUpper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";12const byte s_hexLower[] = "0123456789abcdefghijklmnopqrstuv";1314const int s_array[256] = {15-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,16-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,17-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,18-1, -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1,19-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,2013, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, -1, -1, -1,21-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,2213, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -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, -1,29-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,30-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -131};3233const int s_hexArray[256] = {34-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,35-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,36-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,370, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,38-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,3925, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1,40-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,4125, 26, 27, 28, 29, 30, 31, -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-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,48-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,49-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -150};5152ANONYMOUS_NAMESPACE_END5354void Base32Encoder::IsolatedInitialize(const NameValuePairs ¶meters)55{56bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);57m_filter->Initialize(CombinedNameValuePairs(58parameters,59MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_stdUpper[0] : &s_stdLower[0], false)(Name::Log2Base(), 5, true)));60}6162void Base32Decoder::IsolatedInitialize(const NameValuePairs ¶meters)63{64BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(65parameters,66MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));67}6869// Unrolled initialization, http://github.com/weidai11/cryptopp/issues/37670const int *Base32Decoder::GetDefaultDecodingLookupArray()71{72return s_array;73}7475void Base32HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters)76{77bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);78m_filter->Initialize(CombinedNameValuePairs(79parameters,80MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_hexUpper[0] : &s_hexLower[0], false)(Name::Log2Base(), 5, true)));81}8283void Base32HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters)84{85BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(86parameters,87MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));88}8990// Unrolled initialization, http://github.com/weidai11/cryptopp/issues/37691const int *Base32HexDecoder::GetDefaultDecodingLookupArray()92{93return s_hexArray;94}9596NAMESPACE_END979899