6 #ifndef CRYPTOPP_IMPORTS 19 if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
20 throw InvalidArgument(
"BaseN_Encoder: Log2Base must be between 1 and 7 inclusive");
28 m_padding = pad ? padding : -1;
30 m_bytePos = m_bitPos = 0;
33 while (i%m_bitsPerChar != 0)
35 m_outputBlockSize = i/m_bitsPerChar;
37 m_outBuf.
New(m_outputBlockSize);
43 while (m_inputPosition < length)
46 std::memset(m_outBuf, 0, m_outputBlockSize);
49 unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8;
53 unsigned int bitsLeftInTarget = (
unsigned int)(m_bitsPerChar-m_bitPos);
54 m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget);
55 if (bitsLeftInSource >= bitsLeftInTarget)
59 bitsLeftInSource -= bitsLeftInTarget;
60 if (bitsLeftInSource == 0)
62 b <<= bitsLeftInTarget;
67 m_bitPos += bitsLeftInSource;
74 if (m_bytePos == m_outputBlockSize)
77 for (i=0; i<m_bytePos; i++)
80 m_outBuf[i] = m_alphabet[m_outBuf[i]];
82 FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0);
84 m_bytePos = m_bitPos = 0;
93 for (i=0; i<m_bytePos; i++)
94 m_outBuf[i] = m_alphabet[m_outBuf[i]];
96 if (m_padding != -1 && m_bytePos > 0)
98 std::memset(m_outBuf+m_bytePos, m_padding, m_outputBlockSize-m_bytePos);
99 m_bytePos = m_outputBlockSize;
101 FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd);
102 m_bytePos = m_bitPos = 0;
104 FILTER_END_NO_MESSAGE_END;
112 if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
113 throw InvalidArgument(
"BaseN_Decoder: Log2Base must be between 1 and 7 inclusive");
115 m_bytePos = m_bitPos = 0;
117 int i = m_bitsPerChar;
120 m_outputBlockSize = i/8;
122 m_outBuf.
New(m_outputBlockSize);
128 while (m_inputPosition < length)
131 value = m_lookup[begin[m_inputPosition++]];
135 if (m_bytePos == 0 && m_bitPos == 0)
136 std::memset(m_outBuf, 0, m_outputBlockSize);
139 int newBitPos = m_bitPos + m_bitsPerChar;
141 m_outBuf[m_bytePos] |= value << (8-newBitPos);
144 m_outBuf[m_bytePos] |= value >> (newBitPos-8);
145 m_outBuf[m_bytePos+1] |= value << (16-newBitPos);
148 m_bitPos = newBitPos;
149 while (m_bitPos >= 8)
156 if (m_bytePos == m_outputBlockSize)
158 FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0);
159 m_bytePos = m_bitPos = 0;
164 FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd);
165 m_bytePos = m_bitPos = 0;
167 FILTER_END_NO_MESSAGE_END;
172 std::fill(lookup, lookup+256, -1);
174 for (
unsigned int i=0; i<base; i++)
179 if (caseInsensitive && isalpha(alphabet[i]))
181 lookup[toupper(alphabet[i])] = i;
182 lookup[tolower(alphabet[i])] = i;
186 lookup[alphabet[i]] = i;
206 size_t Grouper::Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
211 while (m_inputPosition < length)
213 if (m_counter == m_groupSize)
215 FILTER_OUTPUT(1, m_separator, m_separator.
size(), 0);
220 FILTER_OUTPUT2(2, (len =
STDMIN(length-m_inputPosition, m_groupSize-m_counter)),
221 begin+m_inputPosition, len, 0);
222 m_inputPosition += len;
227 FILTER_OUTPUT(3, begin, length, 0);
231 FILTER_OUTPUT(4, m_terminator, m_terminator.
size(), messageEnd);
234 FILTER_END_NO_MESSAGE_END
Used to pass byte array input as part of a NameValuePairs object.
An invalid argument was detected.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
size_t size() const
Length of the memory block.
static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive)
Initializes BaseN lookup array.
Library configuration file.
void New(size_type newSize)
Change size without preserving contents.
CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
const char * PaddingByte()
byte
const char * Separator()
ConstByteArrayParameter.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
const byte * begin() const
Pointer to the first byte in the memory block.
const char * EncodingLookupArray()
const byte *
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
const char * Log2Base()
int
const char * GroupSize()
int
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
const char * Terminator()
ConstByteArrayParameter.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
unsigned char byte
8-bit unsigned datatype
const char * DecodingLookupArray()
const byte *
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
Base classes for working with encoders and decoders.
size_type size() const
Provides the count of elements in the SecBlock.
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.