diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /src/pipe_io.cpp |
Initial checkin1.5.6
Diffstat (limited to 'src/pipe_io.cpp')
-rw-r--r-- | src/pipe_io.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pipe_io.cpp b/src/pipe_io.cpp new file mode 100644 index 000000000..ae3a8825f --- /dev/null +++ b/src/pipe_io.cpp @@ -0,0 +1,43 @@ +/************************************************* +* Pipe I/O Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/pipe.h> +#include <iostream> + +namespace Botan { + +/************************************************* +* Write data from a pipe into an ostream * +*************************************************/ +std::ostream& operator<<(std::ostream& stream, Pipe& pipe) + { + SecureVector<byte> buffer(DEFAULT_BUFFERSIZE); + while(stream.good() && pipe.remaining()) + { + u32bit got = pipe.read(buffer, buffer.size()); + stream.write((const char*)buffer.begin(), got); + } + if(!stream.good()) + throw Stream_IO_Error("Pipe output operator (iostream) has failed"); + return stream; + } + +/************************************************* +* Read data from an istream into a pipe * +*************************************************/ +std::istream& operator>>(std::istream& stream, Pipe& pipe) + { + SecureVector<byte> buffer(DEFAULT_BUFFERSIZE); + while(stream.good()) + { + stream.read((char*)buffer.begin(), buffer.size()); + pipe.write(buffer, stream.gcount()); + } + if(stream.bad() || (stream.fail() && !stream.eof())) + throw Stream_IO_Error("Pipe input operator (iostream) has failed"); + return stream; + } + +} |