aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-12-22 20:42:14 -0500
committerJack Lloyd <[email protected]>2016-12-22 20:42:14 -0500
commitbcae34c0c083870dcdc307d9b3d0b24dc3a2a9cf (patch)
treeb702af1f3503dee14649e39e5d1ee1da85e4c6b7 /src/lib
parent3bd0ea1d3425014667daab3d23d549bcacb46f0a (diff)
More filter tests
Expose Data{Source,Sink}_Stream types even if no filesystem is available. Instead just guard the constructors taking a pathname.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/filters/data_snk.cpp14
-rw-r--r--src/lib/filters/data_snk.h22
-rw-r--r--src/lib/utils/data_src.cpp14
-rw-r--r--src/lib/utils/data_src.h11
4 files changed, 28 insertions, 33 deletions
diff --git a/src/lib/filters/data_snk.cpp b/src/lib/filters/data_snk.cpp
index e6dc0d671..7a213cfeb 100644
--- a/src/lib/filters/data_snk.cpp
+++ b/src/lib/filters/data_snk.cpp
@@ -15,7 +15,6 @@
namespace Botan {
-#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* Write to a stream
*/
@@ -33,35 +32,34 @@ void DataSink_Stream::write(const uint8_t out[], size_t length)
DataSink_Stream::DataSink_Stream(std::ostream& out,
const std::string& name) :
m_identifier(name),
- m_sink_p(nullptr),
m_sink(out)
{
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/*
* DataSink_Stream Constructor
*/
DataSink_Stream::DataSink_Stream(const std::string& path,
bool use_binary) :
m_identifier(path),
- m_sink_p(new std::ofstream(path,
- use_binary ? std::ios::binary : std::ios::out)),
- m_sink(*m_sink_p)
+ m_sink_memory(new std::ofstream(path, use_binary ? std::ios::binary : std::ios::out)),
+ m_sink(*m_sink_memory)
{
if(!m_sink.good())
{
- delete m_sink_p;
throw Stream_IO_Error("DataSink_Stream: Failure opening " + path);
}
}
+#endif
/*
* DataSink_Stream Destructor
*/
DataSink_Stream::~DataSink_Stream()
{
- delete m_sink_p;
+ // for ~unique_ptr
}
-#endif
}
diff --git a/src/lib/filters/data_snk.h b/src/lib/filters/data_snk.h
index 46aef285c..4c70d7f19 100644
--- a/src/lib/filters/data_snk.h
+++ b/src/lib/filters/data_snk.h
@@ -9,6 +9,7 @@
#define BOTAN_DATA_SINK_H__
#include <botan/filter.h>
+#include <memory>
#include <iosfwd>
namespace Botan {
@@ -27,18 +28,12 @@ class BOTAN_DLL DataSink : public Filter
DataSink(const DataSink&) = delete;
};
-#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
-
/**
* This class represents a data sink which writes its output to a stream.
*/
class BOTAN_DLL DataSink_Stream : public DataSink
{
public:
- std::string name() const override { return m_identifier; }
-
- void write(const uint8_t[], size_t) override;
-
/**
* Construct a DataSink_Stream from a stream.
* @param stream the stream to write to
@@ -47,25 +42,32 @@ class BOTAN_DLL DataSink_Stream : public DataSink
DataSink_Stream(std::ostream& stream,
const std::string& name = "<std::ostream>");
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/**
- * Construct a DataSink_Stream from a stream.
+ * Construct a DataSink_Stream from a filesystem path name.
* @param pathname the name of the file to open a stream to
* @param use_binary indicates whether to treat the file
* as a binary file or not
*/
DataSink_Stream(const std::string& pathname,
bool use_binary = false);
+#endif
+
+ std::string name() const override { return m_identifier; }
+
+ void write(const uint8_t[], size_t) override;
~DataSink_Stream();
+
private:
const std::string m_identifier;
- std::ostream* m_sink_p;
+ // May be null, if m_sink was an external reference
+ std::unique_ptr<std::ostream> m_sink_memory;
std::ostream& m_sink;
};
-#endif
-
}
#endif
diff --git a/src/lib/utils/data_src.cpp b/src/lib/utils/data_src.cpp
index 169f8e186..55202daac 100644
--- a/src/lib/utils/data_src.cpp
+++ b/src/lib/utils/data_src.cpp
@@ -101,8 +101,6 @@ DataSource_Memory::DataSource_Memory(const std::string& in) :
{
}
-#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
-
/*
* Read from a stream
*/
@@ -176,6 +174,8 @@ std::string DataSource_Stream::id() const
return m_identifier;
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/*
* DataSource_Stream Constructor
*/
@@ -194,26 +194,22 @@ DataSource_Stream::DataSource_Stream(const std::string& path,
}
}
+#endif
+
/*
* DataSource_Stream Constructor
*/
DataSource_Stream::DataSource_Stream(std::istream& in,
const std::string& name) :
m_identifier(name),
- m_source_p(nullptr),
m_source(in),
m_total_read(0)
{
}
-/*
-* DataSource_Stream Destructor
-*/
DataSource_Stream::~DataSource_Stream()
{
- delete m_source_p;
+ // for ~unique_ptr
}
-#endif
-
}
diff --git a/src/lib/utils/data_src.h b/src/lib/utils/data_src.h
index ea28b7602..29f557606 100644
--- a/src/lib/utils/data_src.h
+++ b/src/lib/utils/data_src.h
@@ -137,8 +137,6 @@ class BOTAN_DLL DataSource_Memory : public DataSource
size_t m_offset;
};
-#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
-
/**
* This class represents a Stream-Based DataSource.
*/
@@ -154,12 +152,14 @@ class BOTAN_DLL DataSource_Stream : public DataSource
DataSource_Stream(std::istream&,
const std::string& id = "<std::istream>");
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
- * Construct a Stream-Based DataSource from file
- * @param file the name of the file
+ * Construct a Stream-Based DataSource from filesystem path
+ * @param file the path to the file
* @param use_binary whether to treat the file as binary or not
*/
DataSource_Stream(const std::string& file, bool use_binary = false);
+#endif
DataSource_Stream(const DataSource_Stream&) = delete;
@@ -171,13 +171,12 @@ class BOTAN_DLL DataSource_Stream : public DataSource
private:
const std::string m_identifier;
+ std::unique_ptr<std::istream> m_source_memory;
std::istream* m_source_p;
std::istream& m_source;
size_t m_total_read;
};
-#endif
-
}
#endif