summaryrefslogtreecommitdiffstats
path: root/botan/src/filters/pipe_io.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'botan/src/filters/pipe_io.cpp')
-rw-r--r--botan/src/filters/pipe_io.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/botan/src/filters/pipe_io.cpp b/botan/src/filters/pipe_io.cpp
new file mode 100644
index 0000000..c57be6d
--- /dev/null
+++ b/botan/src/filters/pipe_io.cpp
@@ -0,0 +1,45 @@
+/*
+* Pipe I/O
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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(reinterpret_cast<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(reinterpret_cast<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;
+ }
+
+}