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