Botan: src/filters/pipe_io.cpp Source File

Botan 1.10.16

pipe_io.cpp
Go to the documentation of this file.
1 /*
2 * Pipe I/O
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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 SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
19 while(stream.good() && pipe.remaining())
20 {
21 size_t got = pipe.read(&buffer[0], buffer.size());
22 stream.write(reinterpret_cast<const char*>(&buffer[0]), 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 SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
35 while(stream.good())
36 {
37 stream.read(reinterpret_cast<char*>(&buffer[0]), buffer.size());
38 pipe.write(&buffer[0], 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:165
Botan::Pipe::remaining
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
Definition: pipe_rw.cpp:138
Botan::Pipe::read
size_t read(byte output[], size_t length)
Definition: pipe_rw.cpp:89
Botan::Pipe::write
void write(const byte in[], size_t length)
Definition: pipe_rw.cpp:34
Botan::operator>>
int operator>>(int fd, Pipe &pipe)
Definition: fd_unix.cpp:39
Botan::operator<<
int operator<<(int fd, Pipe &pipe)
Definition: fd_unix.cpp:17
Botan
Definition: algo_base.h:14
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::SecureVector< byte >
Botan::Pipe
Definition: pipe.h:25