3
* (C) 1999-2007 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/pipe.h>
15
* Write data from a pipe into an ostream
17
std::ostream& operator<<(std::ostream& stream, Pipe& pipe)
19
secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
20
while(stream.good() && pipe.remaining())
22
const size_t got = pipe.read(buffer.data(), buffer.size());
23
stream.write(cast_uint8_ptr_to_char(buffer.data()), got);
26
throw Stream_IO_Error("Pipe output operator (iostream) has failed");
31
* Read data from an istream into a pipe
33
std::istream& operator>>(std::istream& stream, Pipe& pipe)
35
secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
38
stream.read(cast_uint8_ptr_to_char(buffer.data()), buffer.size());
39
const size_t got = static_cast<size_t>(stream.gcount());
40
pipe.write(buffer.data(), got);
42
if(stream.bad() || (stream.fail() && !stream.eof()))
43
throw Stream_IO_Error("Pipe input operator (iostream) has failed");