Crypto++
8.6
Free C++ class library of cryptographic schemes
|
5 #ifndef CRYPTOPP_IMPORTS
13 ANONYMOUS_NAMESPACE_BEGIN
18 class IosExceptionMask
21 IosExceptionMask(std::istream& stream) : m_stream(stream) {
22 m_mask = m_stream.exceptions();
23 m_stream.exceptions(
static_cast<std::ios::iostate
>(0));
26 IosExceptionMask(std::istream& stream, std::ios::iostate newMask) : m_stream(stream) {
27 m_mask = m_stream.exceptions();
28 m_stream.exceptions(newMask);
32 m_stream.exceptions(m_mask);
36 std::istream& m_stream;
37 std::ios::iostate m_mask;
40 ANONYMOUS_NAMESPACE_END
44 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
45 void Files_TestInstantiations()
59 const char *fileName = NULLPTR;
60 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
61 const wchar_t *fileNameWide = NULLPTR;
71 m_file.reset(
new std::ifstream);
72 #ifdef CRYPTOPP_UNIX_AVAILABLE
75 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
80 m_file->open(fileNameWide, std::ios::in | binary);
87 m_file->open(fileName, std::ios::in | binary);
89 throw OpenErr(fileName);
91 m_stream = m_file.get();
100 IosExceptionMask guard(*m_stream);
104 std::streampos current = m_stream->tellg();
105 std::streampos end = m_stream->seekg(0, std::ios::end).tellg();
107 m_stream->seekg(current);
112 if (end ==
static_cast<std::streampos
>(-1))
126 lword size=transferBytes;
132 size_t spaceSize, blockedBytes;
133 while (size && m_stream->good())
137 m_stream->read((
char *)m_space, (std::streamsize)
STDMIN(size, (
lword)spaceSize));
138 m_len = (size_t)m_stream->gcount();
142 m_waiting = blockedBytes > 0;
146 transferBytes += m_len;
149 if (!m_stream->good() && !m_stream->eof())
160 if (begin == 0 && end == 1)
162 int result = m_stream->peek();
163 if (result == std::char_traits<char>::eof())
167 size_t blockedBytes = target.
ChannelPut(channel,
byte(result), blocking);
168 begin += 1-blockedBytes;
174 std::streampos current = m_stream->tellg();
175 std::streampos endPosition = m_stream->seekg(0, std::ios::end).tellg();
176 std::streampos newPosition = current +
static_cast<std::streamoff
>(begin);
178 if (newPosition >= endPosition)
180 m_stream->seekg(current);
183 m_stream->seekg(newPosition);
187 lword copyMax = end-begin;
188 size_t blockedBytes =
const_cast<FileStore *
>(
this)->
TransferTo2(target, copyMax, channel, blocking);
192 const_cast<FileStore *
>(
this)->m_waiting =
false;
199 m_stream->seekg(current);
203 m_stream->seekg(current);
213 lword oldPos = m_stream->tellg();
214 std::istream::off_type offset;
217 m_stream->seekg(offset, std::ios::cur);
218 return (
lword)m_stream->tellg() - oldPos;
226 const char *fileName = NULLPTR;
227 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
228 const wchar_t *fileNameWide = NULLPTR;
238 m_file.reset(
new std::ofstream);
239 #ifdef CRYPTOPP_UNIX_AVAILABLE
240 std::string narrowed;
242 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
243 #elif (CRYPTOPP_MSC_VERSION >= 1400)
246 m_file->open(fileNameWide, std::ios::out | std::ios::trunc | binary);
253 m_file->open(fileName, std::ios::out | std::ios::trunc | binary);
255 throw OpenErr(fileName);
257 m_stream = m_file.get();
262 CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking);
264 throw Err(
"FileSink: output stream not opened");
267 if (!m_stream->good())
273 size_t FileSink::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
275 CRYPTOPP_UNUSED(blocking);
277 throw Err(
"FileSink: output stream not opened");
281 std::streamsize size;
283 size = ((std::numeric_limits<std::streamsize>::max)());
284 m_stream->write((
const char *)inString, size);
286 length -= (size_t)size;
292 if (!m_stream->good())
const char * OutputBinaryMode()
bool
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
const char * OutputStreamPointer()
std::ostream *
const char * InputStreamPointer()
std::istream *
Implementation of Store interface.
const char * OutputFileName()
const char *
const char * InputBinaryMode()
bool
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
const char * InputFileNameWide()
const wchar_t *
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.
#define SIZE_MAX
The maximum value of a machine word.
bool SafeConvert(T1 from, T2 &to)
Tests whether a conversion from -> to is safe to perform.
Implementation of Store interface.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
Create a working space in a BufferedTransformation.
lword Skip(lword skipMax=ULONG_MAX)
Discard skipMax bytes from the output buffer.
const char * OutputFileNameWide()
const wchar_t *
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
Copy bytes from this object to another BufferedTransformation.
word64 lword
Large word type.
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
An invalid argument was detected.
std::string StringNarrow(const wchar_t *str, bool throwOnError=true)
Converts a wide character C-string to a multibyte string.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
Implementation of Store interface.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Classes providing file-based library services.
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
const char * InputFileName()
const char *
const lword LWORD_MAX
Large word type max value.
Interface for retrieving values given their names.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.