Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

pipe_io.cpp
Go to the documentation of this file.
1 /*
2 * Pipe I/O
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/pipe.h>
9 #include <iostream>
10
11 namespace Botan {
12
13 /*
14 * Write data from a pipe into an ostream
15 */
16 std::ostream& operator<<(std::ostream& stream, Pipe& pipe)
17 {
18 secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
19 while(stream.good() && pipe.remaining())
20 {
21 size_t got = pipe.read(buffer.data(), buffer.size());
22 stream.write(reinterpret_cast<const char*>(buffer.data()), got);
23 }
24 if(!stream.good())
25 throw Stream_IO_Error("Pipe output operator (iostream) has failed");
26 return stream;
27 }
28
29 /*
30 * Read data from an istream into a pipe
31 */
32 std::istream& operator>>(std::istream& stream, Pipe& pipe)
33 {
34 secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
35 while(stream.good())
36 {
37 stream.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
38 pipe.write(buffer.data(), stream.gcount());
39 }
40 if(stream.bad() || (stream.fail() && !stream.eof()))
41 throw Stream_IO_Error("Pipe input operator (iostream) has failed");
42 return stream;
43 }
44
45 }
Botan::Stream_IO_Error
Definition: exceptn.h:216
Botan::operator>>
std::istream & operator>>(std::istream &in, X509_DN &dn)
Definition: x509_dn.cpp:325
Botan::Pipe::remaining
size_t remaining(message_id msg=DEFAULT_MESSAGE) const BOTAN_WARN_UNUSED_RESULT
Definition: pipe_rw.cpp:130
Botan::operator<<
std::ostream & operator<<(std::ostream &out, const X509_DN &dn)
Definition: x509_dn.cpp:299
Botan::Pipe::read
size_t read(uint8_t output[], size_t length) override BOTAN_WARN_UNUSED_RESULT
Definition: pipe_rw.cpp:81
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan
Definition: alg_id.cpp:13
Botan::Pipe
Definition: pipe.h:27
Botan::Pipe::write
void write(const uint8_t in[], size_t length)
Definition: pipe_rw.cpp:34