Botan 3.4.0
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
10#include <botan/mem_ops.h>
11#include <istream>
12#include <ostream>
13
14namespace Botan {
15
16/*
17* Write data from a pipe into an ostream
18*/
19std::ostream& operator<<(std::ostream& stream, Pipe& pipe) {
21 while(stream.good() && pipe.remaining()) {
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 }
28 return stream;
29}
30
31/*
32* Read data from an istream into a pipe
33*/
34std::istream& operator>>(std::istream& stream, Pipe& pipe) {
36 while(stream.good()) {
37 stream.read(cast_uint8_ptr_to_char(buffer.data()), buffer.size());
38 const size_t got = static_cast<size_t>(stream.gcount());
39 pipe.write(buffer.data(), got);
40 }
41 if(stream.bad() || (stream.fail() && !stream.eof())) {
42 throw Stream_IO_Error("Pipe input operator (iostream) has failed");
43 }
44 return stream;
45}
46
47} // namespace Botan
size_t read(uint8_t output[], size_t length) override
Definition pipe_rw.cpp:79
void write(const uint8_t in[], size_t length)
Definition pipe_rw.cpp:37
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
Definition pipe_rw.cpp:124
#define BOTAN_DEFAULT_BUFFER_SIZE
Definition build.h:391
std::ostream & operator<<(std::ostream &out, const OID &oid)
Definition asn1_oid.cpp:140
int operator>>(int fd, Pipe &pipe)
Definition fd_unix.cpp:39
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:279
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61