5 #ifndef CRYPTOPP_IMPORTS 13 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 14 void Files_TestInstantiations()
28 const char *fileName = NULLPTR;
29 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 30 const wchar_t *fileNameWide = NULLPTR;
40 m_file.reset(
new std::ifstream);
41 #ifdef CRYPTOPP_UNIX_AVAILABLE 44 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
49 m_file->open(fileNameWide, std::ios::in | binary);
56 m_file->open(fileName, std::ios::in | binary);
58 throw OpenErr(fileName);
60 m_stream = m_file.get();
68 std::streampos current = m_stream->tellg();
69 std::streampos end = m_stream->seekg(0, std::ios::end).tellg();
70 m_stream->seekg(current);
82 lword size=transferBytes;
88 while (size && m_stream->good())
91 size_t spaceSize = 1024;
94 m_stream->read((
char *)m_space, (
unsigned int)
STDMIN(size, (lword)spaceSize));
96 m_len = (size_t)m_stream->gcount();
100 m_waiting = blockedBytes > 0;
104 transferBytes += m_len;
107 if (!m_stream->good() && !m_stream->eof())
118 if (begin == 0 && end == 1)
120 int result = m_stream->peek();
121 if (result == std::char_traits<char>::eof())
125 size_t blockedBytes = target.
ChannelPut(channel, byte(result), blocking);
126 begin += 1-blockedBytes;
132 std::streampos current = m_stream->tellg();
133 std::streampos endPosition = m_stream->seekg(0, std::ios::end).tellg();
134 std::streampos newPosition = current +
static_cast<std::streamoff
>(begin);
136 if (newPosition >= endPosition)
138 m_stream->seekg(current);
141 m_stream->seekg(newPosition);
145 lword copyMax = end-begin;
146 size_t blockedBytes =
const_cast<FileStore *
>(
this)->
TransferTo2(target, copyMax, channel, blocking);
150 const_cast<FileStore *
>(
this)->m_waiting =
false;
157 m_stream->seekg(current);
161 m_stream->seekg(current);
171 lword oldPos = m_stream->tellg();
172 std::istream::off_type offset;
175 m_stream->seekg(offset, std::ios::cur);
176 return (lword)m_stream->tellg() - oldPos;
184 const char *fileName = NULLPTR;
185 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 186 const wchar_t *fileNameWide = NULLPTR;
196 m_file.reset(
new std::ofstream);
197 #ifdef CRYPTOPP_UNIX_AVAILABLE 198 std::string narrowed;
200 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
201 #elif (CRYPTOPP_MSC_VERSION >= 1400) 204 m_file->open(fileNameWide, std::ios::out | std::ios::trunc | binary);
211 m_file->open(fileName, std::ios::out | std::ios::trunc | binary);
215 m_stream = m_file.get();
220 CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking);
222 throw Err(
"FileSink: output stream not opened");
225 if (!m_stream->good())
231 size_t FileSink::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
233 CRYPTOPP_UNUSED(blocking);
235 throw Err(
"FileSink: output stream not opened");
239 std::streamsize size;
241 size = ((std::numeric_limits<std::streamsize>::max)());
242 m_stream->write((
const char *)inString, size);
244 length -= (size_t)size;
250 if (!m_stream->good())
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.
const char * InputFileNameWide()
const wchar_t *
bool SafeConvert(T1 from, T2 &to)
Tests whether a conversion from -> to is safe to perform.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
Implementation of Store interface.
const char * OutputStreamPointer()
std::ostream *
const char * InputFileName()
const char *
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
const char * InputStreamPointer()
std::istream *
const char * OutputBinaryMode()
bool
lword Skip(lword skipMax=ULONG_MAX)
Discard skipMax bytes from the output buffer.
const char * OutputFileName()
const char *
Exception thrown when file-based write error is encountered.
Exception thrown when file-based error is encountered.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Implementation of Store interface.
Exception thrown when file-based open error is encountered.
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.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
Classes providing file-based library services.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
const char * InputBinaryMode()
bool
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
Create a working space in a BufferedTransformation.
Implementation of Store interface.
Exception thrown when file-based read error is encountered.
const char * OutputFileNameWide()
const wchar_t *
#define SIZE_MAX
The maximum value of a machine word.
Interface for retrieving values given their names.