Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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