5 #ifndef CRYPTOPP_IMPORTS
11 NAMESPACE_BEGIN(CryptoPP)
16 void Files_TestInstantiations()
30 const char *fileName = NULL;
31 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
32 const wchar_t *fileNameWide = NULL;
42 m_file.reset(
new std::ifstream);
43 #ifdef CRYPTOPP_UNIX_AVAILABLE
46 fileName = (narrowed = StringNarrow(fileNameWide)).c_str();
51 m_file->open(fileNameWide, ios::in | binary);
53 throw OpenErr(StringNarrow(fileNameWide,
false));
58 m_file->open(fileName, ios::in | binary);
60 throw OpenErr(fileName);
62 m_stream = m_file.get();
70 streampos current = m_stream->tellg();
71 streampos end = m_stream->seekg(0, ios::end).tellg();
72 m_stream->seekg(current);
84 lword size=transferBytes;
90 while (size && m_stream->good())
93 size_t spaceSize = 1024;
94 m_space = HelpCreatePutSpace(target, channel, 1, UnsignedMin(
size_t(0)-1, size), spaceSize);
96 m_stream->read((
char *)m_space, (
unsigned int)STDMIN(size, (lword)spaceSize));
98 m_len = (size_t)m_stream->gcount();
101 blockedBytes = target.ChannelPutModifiable2(channel, m_space, m_len, 0, blocking);
102 m_waiting = blockedBytes > 0;
106 transferBytes += m_len;
109 if (!m_stream->good() && !m_stream->eof())
120 if (begin == 0 && end == 1)
122 int result = m_stream->peek();
123 if (result == char_traits<char>::eof())
127 size_t blockedBytes = target.ChannelPut(channel, byte(result), blocking);
128 begin += 1-blockedBytes;
134 streampos current = m_stream->tellg();
135 streampos endPosition = m_stream->seekg(0, ios::end).tellg();
136 streampos newPosition = current + (streamoff)begin;
138 if (newPosition >= endPosition)
140 m_stream->seekg(current);
143 m_stream->seekg(newPosition);
147 lword copyMax = end-begin;
148 size_t blockedBytes =
const_cast<FileStore *
>(
this)->
TransferTo2(target, copyMax, channel, blocking);
152 const_cast<FileStore *
>(
this)->m_waiting =
false;
159 m_stream->seekg(current);
163 m_stream->seekg(current);
173 lword oldPos = m_stream->tellg();
174 std::istream::off_type offset;
175 if (!SafeConvert(skipMax, offset))
177 m_stream->seekg(offset, ios::cur);
178 return (lword)m_stream->tellg() - oldPos;
181 void FileSink::IsolatedInitialize(
const NameValuePairs ¶meters)
186 const char *fileName = NULL;
187 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
188 const wchar_t *fileNameWide = NULL;
198 m_file.reset(
new std::ofstream);
199 #ifdef CRYPTOPP_UNIX_AVAILABLE
200 std::string narrowed;
202 fileName = (narrowed = StringNarrow(fileNameWide)).c_str();
207 m_file->open(fileNameWide, ios::out | ios::trunc | binary);
209 throw OpenErr(StringNarrow(fileNameWide,
false));
214 m_file->open(fileName, ios::out | ios::trunc | binary);
216 throw OpenErr(fileName);
218 m_stream = m_file.get();
221 bool FileSink::IsolatedFlush(
bool hardFlush,
bool blocking)
224 throw Err(
"FileSink: output stream not opened");
227 if (!m_stream->good())
233 size_t FileSink::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
236 throw Err(
"FileSink: output stream not opened");
240 std::streamsize size;
241 if (!SafeConvert(length, size))
242 size = numeric_limits<std::streamsize>::max();
243 m_stream->write((
const char *)inString, size);
245 length -= (size_t)size;
251 if (!m_stream->good())
exception thrown when an invalid argument is detected
const char * InputFileNameWide()
const wchar_t *
T GetValueWithDefault(const char *name, T defaultValue) const
get a named value, returns the default if the name doesn't exist
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block
file-based implementation of Source interface
lword MaxRetrievable() const
returns number of bytes that is currently ready for retrieval
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 blocking or non-blocking processing
const char * InputStreamPointer()
std::istream *
const char * OutputBinaryMode()
bool
bool GetValue(const char *name, T &value) const
get a named value, returns true if the name exists
lword Skip(lword skipMax=ULONG_MAX)
discard skipMax bytes from the output buffer
const char * OutputFileName()
const char *
file-based implementation of Store interface
const char * InputBinaryMode()
bool
file-based implementation of Sink interface
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block
const char * OutputFileNameWide()
const wchar_t *
interface for retrieving values given their names