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 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 assert(m_bitPos < m_bitsPerChar);
61 unsigned int bitsLeftInTarget = 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 assert(m_bytePos <= m_outputBlockSize);
82 if (m_bytePos == m_outputBlockSize)
85 for (i=0; i<m_bytePos; i++)
87 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++)
184 if (caseInsensitive && isalpha(alphabet[i]))
186 assert(lookup[toupper(alphabet[i])] == -1);
187 lookup[toupper(alphabet[i])] = i;
188 assert(lookup[tolower(alphabet[i])] == -1);
189 lookup[tolower(alphabet[i])] = i;
193 assert(lookup[alphabet[i]] == -1);
194 lookup[alphabet[i]] = i;
206 parameters.
GetValue(Name::Separator(), separator);
207 parameters.
GetValue(Name::Terminator(), terminator);
209 m_separator.Assign(separator.begin(), separator.size());
210 m_terminator.Assign(terminator.begin(), terminator.size());
214 size_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
used to pass byte array input as part of a NameValuePairs object
An invalid argument was detected.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
Library configuration file.
void New(size_type newSize)
Change size without preserving contents.
static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive)
Intializes BaseN lookup array.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
bool GetValue(const char *name, T &value) const
Get a named value.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Crypto++ library namespace.
Encoder for bases that are a power of 2.
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.
Interface for retrieving values given their names.