Botan  2.1.0
Crypto and TLS for C++11
data_snk.cpp
Go to the documentation of this file.
1 /*
2 * DataSink
3 * (C) 1999-2007 Jack Lloyd
4 * 2005 Matthew Gregan
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #include <botan/data_snk.h>
10 #include <botan/exceptn.h>
11 
12 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
13  #include <fstream>
14 #endif
15 
16 namespace Botan {
17 
18 /*
19 * Write to a stream
20 */
21 void DataSink_Stream::write(const uint8_t out[], size_t length)
22  {
23  m_sink.write(reinterpret_cast<const char*>(out), length);
24  if(!m_sink.good())
25  throw Stream_IO_Error("DataSink_Stream: Failure writing to " +
26  m_identifier);
27  }
28 
29 /*
30 * DataSink_Stream Constructor
31 */
33  const std::string& name) :
34  m_identifier(name),
35  m_sink(out)
36  {
37  }
38 
39 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
40 
41 /*
42 * DataSink_Stream Constructor
43 */
44 DataSink_Stream::DataSink_Stream(const std::string& path,
45  bool use_binary) :
46  m_identifier(path),
47  m_sink_memory(new std::ofstream(path, use_binary ? std::ios::binary : std::ios::out)),
48  m_sink(*m_sink_memory)
49  {
50  if(!m_sink.good())
51  {
52  throw Stream_IO_Error("DataSink_Stream: Failure opening " + path);
53  }
54  }
55 #endif
56 
57 /*
58 * DataSink_Stream Destructor
59 */
61  {
62  // for ~unique_ptr
63  }
64 
65 }
Definition: bigint.h:619
DataSink_Stream(std::ostream &stream, const std::string &name="<std::ostream>")
Definition: data_snk.cpp:32
Definition: alg_id.cpp:13
void write(const uint8_t[], size_t) override
Definition: data_snk.cpp:21