Crypto++
8.4
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 while (size && m_stream->good())
135 size_t spaceSize = 1024;
138 m_stream->read((
char *)m_space, (
unsigned int)
STDMIN(size, (
lword)spaceSize));
140 m_len = (size_t)m_stream->gcount();
144 m_waiting = blockedBytes > 0;
148 transferBytes += m_len;
151 if (!m_stream->good() && !m_stream->eof())
162 if (begin == 0 && end == 1)
164 int result = m_stream->peek();
165 if (result == std::char_traits<char>::eof())
169 size_t blockedBytes = target.
ChannelPut(channel,
byte(result), blocking);
170 begin += 1-blockedBytes;
176 std::streampos current = m_stream->tellg();
177 std::streampos endPosition = m_stream->seekg(0, std::ios::end).tellg();
178 std::streampos newPosition = current +
static_cast<std::streamoff
>(begin);
180 if (newPosition >= endPosition)
182 m_stream->seekg(current);
185 m_stream->seekg(newPosition);
189 lword copyMax = end-begin;
190 size_t blockedBytes =
const_cast<FileStore *
>(
this)->
TransferTo2(target, copyMax, channel, blocking);
194 const_cast<FileStore *
>(
this)->m_waiting =
false;
201 m_stream->seekg(current);
205 m_stream->seekg(current);
215 lword oldPos = m_stream->tellg();
216 std::istream::off_type offset;
219 m_stream->seekg(offset, std::ios::cur);
220 return (
lword)m_stream->tellg() - oldPos;
228 const char *fileName = NULLPTR;
229 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
230 const wchar_t *fileNameWide = NULLPTR;
240 m_file.reset(
new std::ofstream);
241 #ifdef CRYPTOPP_UNIX_AVAILABLE
242 std::string narrowed;
244 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
245 #elif (CRYPTOPP_MSC_VERSION >= 1400)
248 m_file->open(fileNameWide, std::ios::out | std::ios::trunc | binary);
255 m_file->open(fileName, std::ios::out | std::ios::trunc | binary);
257 throw OpenErr(fileName);
259 m_stream = m_file.get();
264 CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking);
266 throw Err(
"FileSink: output stream not opened");
269 if (!m_stream->good())
275 size_t FileSink::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
277 CRYPTOPP_UNUSED(blocking);
279 throw Err(
"FileSink: output stream not opened");
283 std::streamsize size;
285 size = ((std::numeric_limits<std::streamsize>::max)());
286 m_stream->write((
const char *)inString, size);
288 length -= (size_t)size;
294 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 neagtive 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.