6#if CRYPTOPP_MSC_VERSION
7# pragma warning(disable: 4100)
10#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
11# pragma GCC diagnostic ignored "-Wunused-value"
14#ifndef CRYPTOPP_IMPORTS
20NAMESPACE_BEGIN(CryptoPP)
24 parameters.GetRequiredParameter(
"BaseN_Encoder", Name::EncodingLookupArray(), m_alphabet);
26 parameters.GetRequiredIntParameter(
"BaseN_Encoder", Name::Log2Base(), m_bitsPerChar);
27 if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
28 throw InvalidArgument(
"BaseN_Encoder: Log2Base must be between 1 and 7 inclusive");
32 if (parameters.GetValue(Name::PaddingByte(), padding))
33 pad = parameters.GetValueWithDefault(Name::Pad(),
true);
36 m_padding = pad ? padding : -1;
38 m_bytePos = m_bitPos = 0;
41 while (i%m_bitsPerChar != 0)
43 m_outputBlockSize = i/m_bitsPerChar;
45 m_outBuf.New(m_outputBlockSize);
51 while (m_inputPosition < length)
54 memset(m_outBuf, 0, m_outputBlockSize);
57 unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8;
60 CRYPTOPP_ASSERT(m_bitsPerChar-m_bitPos >= 0);
61 unsigned int bitsLeftInTarget = (
unsigned int)(m_bitsPerChar-m_bitPos);
62 m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget);
63 if (bitsLeftInSource >= bitsLeftInTarget)
67 bitsLeftInSource -= bitsLeftInTarget;
68 if (bitsLeftInSource == 0)
70 b <<= bitsLeftInTarget;
75 m_bitPos += bitsLeftInSource;
81 CRYPTOPP_ASSERT(m_bytePos <= m_outputBlockSize);
82 if (m_bytePos == m_outputBlockSize)
85 for (i=0; i<m_bytePos; i++)
87 CRYPTOPP_ASSERT(m_outBuf[i] < (1 << m_bitsPerChar));
88 m_outBuf[i] = m_alphabet[m_outBuf[i]];
90 FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0);
92 m_bytePos = m_bitPos = 0;
101 for (i=0; i<m_bytePos; i++)
102 m_outBuf[i] = m_alphabet[m_outBuf[i]];
104 if (m_padding != -1 && m_bytePos > 0)
106 memset(m_outBuf+m_bytePos, m_padding, m_outputBlockSize-m_bytePos);
107 m_bytePos = m_outputBlockSize;
109 FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd);
110 m_bytePos = m_bitPos = 0;
112 FILTER_END_NO_MESSAGE_END;
120 if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
121 throw InvalidArgument(
"BaseN_Decoder: Log2Base must be between 1 and 7 inclusive");
123 m_bytePos = m_bitPos = 0;
125 int i = m_bitsPerChar;
128 m_outputBlockSize = i/8;
130 m_outBuf.
New(m_outputBlockSize);
136 while (m_inputPosition < length)
139 value = m_lookup[begin[m_inputPosition++]];
143 if (m_bytePos == 0 && m_bitPos == 0)
144 memset(m_outBuf, 0, m_outputBlockSize);
147 int newBitPos = m_bitPos + m_bitsPerChar;
149 m_outBuf[m_bytePos] |= value << (8-newBitPos);
152 m_outBuf[m_bytePos] |= value >> (newBitPos-8);
153 m_outBuf[m_bytePos+1] |= value << (16-newBitPos);
156 m_bitPos = newBitPos;
157 while (m_bitPos >= 8)
164 if (m_bytePos == m_outputBlockSize)
166 FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0);
167 m_bytePos = m_bitPos = 0;
172 FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd);
173 m_bytePos = m_bitPos = 0;
175 FILTER_END_NO_MESSAGE_END;
180 std::fill(lookup, lookup+256, -1);
182 for (
unsigned int i=0; i<base; i++)
187 if (caseInsensitive && isalpha(alphabet[i]))
189 lookup[toupper(alphabet[i])] = i;
190 lookup[tolower(alphabet[i])] = i;
194 lookup[alphabet[i]] = i;
206 parameters.
GetValue(Name::Separator(), separator);
207 parameters.
GetValue(Name::Terminator(), terminator);
214size_t Grouper::Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
219 while (m_inputPosition < length)
221 if (m_counter == m_groupSize)
223 FILTER_OUTPUT(1, m_separator, m_separator.
size(), 0);
228 FILTER_OUTPUT2(2, len =
STDMIN(length-m_inputPosition, m_groupSize-m_counter),
229 begin+m_inputPosition, len, 0);
230 m_inputPosition += len;
235 FILTER_OUTPUT(3, begin, length, 0);
239 FILTER_OUTPUT(4, m_terminator, m_terminator.
size(), messageEnd);
242 FILTER_END_NO_MESSAGE_END
Base classes for working with encoders and decoders.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive)
Initializes BaseN lookup array.
Encoder for bases that are a power of 2.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Used to pass byte array input as part of a NameValuePairs object.
const byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
An invalid argument was detected.
Interface for retrieving values given their names.
bool GetValue(const char *name, T &value) const
Get a named value.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
void New(size_type newSize)
Change size without preserving contents.
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
size_type size() const
Provides the count of elements in the SecBlock.
Library configuration file.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.