aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilippe Lieser <[email protected]>2017-04-10 16:56:06 +0200
committerPhilippe Lieser <[email protected]>2017-04-10 16:56:06 +0200
commit2b0a0c3b323d3b8fa09a31420738e0663a4590e8 (patch)
tree44d24a88ad2c393987e4ee2eeee4cc87d0e561f5 /src
parent2f1b5f55d736715c6c15a117bcb70ae582cc7920 (diff)
fix missing flush in DataSink_Stream::end_msg
Diffstat (limited to 'src')
-rw-r--r--src/lib/filters/data_snk.cpp9
-rw-r--r--src/lib/filters/data_snk.h3
-rw-r--r--src/tests/test_filters.cpp27
3 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/filters/data_snk.cpp b/src/lib/filters/data_snk.cpp
index 7a213cfeb..38734f0e3 100644
--- a/src/lib/filters/data_snk.cpp
+++ b/src/lib/filters/data_snk.cpp
@@ -2,6 +2,7 @@
* DataSink
* (C) 1999-2007 Jack Lloyd
* 2005 Matthew Gregan
+* 2017 Philippe Lieser
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -27,6 +28,14 @@ void DataSink_Stream::write(const uint8_t out[], size_t length)
}
/*
+* Flush the stream
+*/
+void DataSink_Stream::end_msg()
+ {
+ m_sink.flush();
+ }
+
+/*
* DataSink_Stream Constructor
*/
DataSink_Stream::DataSink_Stream(std::ostream& out,
diff --git a/src/lib/filters/data_snk.h b/src/lib/filters/data_snk.h
index 7accef358..b3e5e06cf 100644
--- a/src/lib/filters/data_snk.h
+++ b/src/lib/filters/data_snk.h
@@ -1,6 +1,7 @@
/*
* DataSink
* (C) 1999-2007 Jack Lloyd
+* 2017 Philippe Lieser
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -58,6 +59,8 @@ class BOTAN_DLL DataSink_Stream : public DataSink
void write(const uint8_t[], size_t) override;
+ void end_msg() override;
+
~DataSink_Stream();
private:
diff --git a/src/tests/test_filters.cpp b/src/tests/test_filters.cpp
index ee3e68c1a..b9bd15ced 100644
--- a/src/tests/test_filters.cpp
+++ b/src/tests/test_filters.cpp
@@ -2,6 +2,7 @@
* (C) 2016 Daniel Neus
* 2016 Jack Lloyd
* 2017 René Korthaus
+* 2017 Philippe Lieser
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -35,6 +36,7 @@ class Filter_Tests : public Test
results.push_back(test_secqueue());
results.push_back(test_data_src_sink());
+ results.push_back(test_data_src_sink_flush());
results.push_back(test_pipe_io());
results.push_back(test_pipe_errors());
results.push_back(test_pipe_hash());
@@ -114,6 +116,31 @@ class Filter_Tests : public Test
return result;
}
+ Test::Result test_data_src_sink_flush()
+ {
+ Test::Result result("DataSinkFlush");
+
+#if defined(BOTAN_HAS_CODEC_FILTERS)
+ std::string tmp_name("botan_test_data_src_sink_flush.tmp");
+ std::ofstream outfile(tmp_name);
+
+ Botan::Pipe pipe(new Botan::Hex_Decoder, new Botan::DataSink_Stream(outfile));
+
+ Botan::DataSource_Memory input_mem("65666768");
+ pipe.process_msg(input_mem);
+
+ std::ifstream outfile_read(tmp_name);
+ std::stringstream ss;
+ ss << outfile_read.rdbuf();
+ std::string foo = ss.str();
+
+ result.test_eq("output string", ss.str(), "efgh");
+
+ std::remove(tmp_name.c_str());
+#endif
+ return result;
+ }
+
Test::Result test_pipe_io()
{
Test::Result result("Pipe I/O operators");