~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/lib/filters/data_snk.h

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <memory>
 
14
#include <iosfwd>
 
15
 
 
16
namespace Botan {
 
17
 
 
18
/**
 
19
* This class represents abstract data sink objects.
 
20
*/
 
21
class BOTAN_PUBLIC_API(2,0) DataSink : public Filter
 
22
   {
 
23
   public:
 
24
      bool attachable() override { return false; }
 
25
      DataSink() = default;
 
26
      virtual ~DataSink() = default;
 
27
 
 
28
      DataSink& operator=(const DataSink&) = delete;
 
29
      DataSink(const DataSink&) = delete;
 
30
   };
 
31
 
 
32
/**
 
33
* This class represents a data sink which writes its output to a stream.
 
34
*/
 
35
class BOTAN_PUBLIC_API(2,0) DataSink_Stream final : public DataSink
 
36
   {
 
37
   public:
 
38
      /**
 
39
      * Construct a DataSink_Stream from a stream.
 
40
      * @param stream the stream to write to
 
41
      * @param name identifier
 
42
      */
 
43
      DataSink_Stream(std::ostream& stream,
 
44
                      const std::string& name = "<std::ostream>");
 
45
 
 
46
#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
 
47
 
 
48
      /**
 
49
      * Construct a DataSink_Stream from a filesystem path name.
 
50
      * @param pathname the name of the file to open a stream to
 
51
      * @param use_binary indicates whether to treat the file
 
52
      * as a binary file or not
 
53
      */
 
54
      DataSink_Stream(const std::string& pathname,
 
55
                      bool use_binary = false);
 
56
#endif
 
57
 
 
58
      std::string name() const override { return m_identifier; }
 
59
 
 
60
      void write(const uint8_t[], size_t) override;
 
61
 
 
62
      void end_msg() override;
 
63
 
 
64
      ~DataSink_Stream();
 
65
 
 
66
   private:
 
67
      const std::string m_identifier;
 
68
 
 
69
      // May be null, if m_sink was an external reference
 
70
      std::unique_ptr<std::ostream> m_sink_memory;
 
71
      std::ostream& m_sink;
 
72
   };
 
73
 
 
74
}
 
75
 
 
76
#endif