aboutsummaryrefslogtreecommitdiffstats
path: root/src/data_snk.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /src/data_snk.cpp
Initial checkin1.5.6
Diffstat (limited to 'src/data_snk.cpp')
-rw-r--r--src/data_snk.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/data_snk.cpp b/src/data_snk.cpp
new file mode 100644
index 000000000..0c7e18984
--- /dev/null
+++ b/src/data_snk.cpp
@@ -0,0 +1,56 @@
+/*************************************************
+* DataSink Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/data_snk.h>
+#include <fstream>
+
+namespace Botan {
+
+/*************************************************
+* Write to a stream *
+*************************************************/
+void DataSink_Stream::write(const byte out[], u32bit length)
+ {
+ sink->write((const char*)out, length);
+ if(!sink->good())
+ throw Stream_IO_Error("DataSink_Stream: Failure writing to " + fsname);
+ }
+
+/*************************************************
+* DataSink_Stream Constructor *
+*************************************************/
+DataSink_Stream::DataSink_Stream(std::ostream& stream) : fsname("std::ostream")
+ {
+ sink = &stream;
+ owns = false;
+ }
+
+/*************************************************
+* DataSink_Stream Constructor *
+*************************************************/
+DataSink_Stream::DataSink_Stream(const std::string& file,
+ bool use_binary) : fsname(file)
+ {
+ if(use_binary)
+ sink = new std::ofstream(fsname.c_str(), std::ios::binary);
+ else
+ sink = new std::ofstream(fsname.c_str());
+
+ if(!sink->good())
+ throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname);
+ owns = true;
+ }
+
+/*************************************************
+* DataSink_Stream Destructor *
+*************************************************/
+DataSink_Stream::~DataSink_Stream()
+ {
+ if(owns)
+ delete sink;
+ sink = 0;
+ }
+
+}