Botan 3.13.0
Crypto and TLS for C&
data_snk.h
Go to the documentation of this file.
1/*
2* DataSink
3* (C) 1999-2007 Jack Lloyd
4* 2017 Philippe Lieser
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_DATA_SINK_H_
10#define BOTAN_DATA_SINK_H_
11
12#include <botan/filter.h>
13#include <iosfwd>
14#include <memory>
15
16namespace Botan {
17
18/**
19* This class represents abstract data sink objects.
20*/
21class BOTAN_PUBLIC_API(2, 0) DataSink : public Filter {
22 public:
23 /**
24 * Check whether this filter is an attachable filter
25 * @return always false, since nothing may be attached after a sink
26 */
27 bool attachable() override { return false; }
28};
29
30/**
31* This class represents a data sink which writes its output to a stream.
32*/
33class BOTAN_PUBLIC_API(2, 0) DataSink_Stream final : public DataSink {
34 public:
35 /**
36 * Construct a DataSink_Stream from a stream.
37 * @param stream the stream to write to
38 * @param name identifier
39 */
40 BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::ostream& stream, std::string_view name = "<std::ostream>");
41
42#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
43
44 /**
45 * Construct a DataSink_Stream from a filesystem path name.
46 * @param pathname the name of the file to open a stream to
47 * @param use_binary indicates whether to treat the file
48 * as a binary file or not
49 */
50 BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::string_view pathname, bool use_binary = false);
51#endif
52
53 DataSink_Stream(const DataSink_Stream& other) = delete;
55 DataSink_Stream& operator=(const DataSink_Stream& other) = delete;
57
58 /**
59 * Return a descriptive name for this filter
60 * @return the identifier given at construction
61 */
62 std::string name() const override { return m_identifier; }
63
64 /**
65 * Write a portion of a message to the stream
66 * @param buf the input as a byte array
67 * @param len the length of the byte array buf
68 */
69 void write(const uint8_t buf[], size_t len) override;
70
71 /**
72 * Notify that the current message is finished and flush the stream
73 */
74 void end_msg() override;
75
76 ~DataSink_Stream() override;
77
78 private:
79 const std::string m_identifier;
80
81 // May be null, if m_sink was an external reference
82 std::unique_ptr<std::ostream> m_sink_memory;
83 std::ostream& m_sink;
84};
85
86} // namespace Botan
87
88#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
std::string name() const override
Definition data_snk.h:62
DataSink_Stream(const DataSink_Stream &other)=delete
DataSink_Stream & operator=(const DataSink_Stream &other)=delete
DataSink_Stream(DataSink_Stream &&other)=delete
DataSink_Stream & operator=(DataSink_Stream &&other)=delete
BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::ostream &stream, std::string_view name="<std::ostream>")
Definition data_snk.cpp:46
~DataSink_Stream() override
bool attachable() override
Definition data_snk.h:27
Filter(const Filter &)=delete