Botan 2.19.2
Crypto and TLS for C&
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 <istream>
10#include <ostream>
11
12namespace Botan {
13
14/*
15* Write data from a pipe into an ostream
16*/
17std::ostream& operator<<(std::ostream& stream, Pipe& pipe)
18 {
19 secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
20 while(stream.good() && pipe.remaining())
21 {
22 const size_t got = pipe.read(buffer.data(), buffer.size());
23 stream.write(cast_uint8_ptr_to_char(buffer.data()), got);
24 }
25 if(!stream.good())
26 throw Stream_IO_Error("Pipe output operator (iostream) has failed");
27 return stream;
28 }
29
30/*
31* Read data from an istream into a pipe
32*/
33std::istream& operator>>(std::istream& stream, Pipe& pipe)
34 {
35 secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
36 while(stream.good())
37 {
38 stream.read(cast_uint8_ptr_to_char(buffer.data()), buffer.size());
39 const size_t got = static_cast<size_t>(stream.gcount());
40 pipe.write(buffer.data(), got);
41 }
42 if(stream.bad() || (stream.fail() && !stream.eof()))
43 throw Stream_IO_Error("Pipe input operator (iostream) has failed");
44 return stream;
45 }
46
47}
size_t read(uint8_t output[], size_t length) override BOTAN_WARN_UNUSED_RESULT
Definition: pipe_rw.cpp:82
void write(const uint8_t in[], size_t length)
Definition: pipe_rw.cpp:35
size_t remaining(message_id msg=DEFAULT_MESSAGE) const BOTAN_WARN_UNUSED_RESULT
Definition: pipe_rw.cpp:131
Definition: alg_id.cpp:13
int operator>>(int fd, Pipe &pipe)
Definition: fd_unix.cpp:40
int operator<<(int fd, Pipe &pipe)
Definition: fd_unix.cpp:17
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition: mem_ops.h:195
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65