Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

fd_unix.cpp
Go to the documentation of this file.
1 /*
2 * Pipe I/O for Unix
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 <botan/exceptn.h>
10 #include <unistd.h>
11
12 namespace Botan {
13
14 /*
15 * Write data from a pipe into a Unix fd
16 */
17 int operator<<(int fd, Pipe& pipe)
18 {
19 secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
20 while(pipe.remaining())
21 {
22 size_t got = pipe.read(buffer.data(), buffer.size());
23 size_t position = 0;
24 while(got)
25 {
26 ssize_t ret = write(fd, &buffer[position], got);
27 if(ret == -1)
28 throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
29 position += ret;
30 got -= ret;
31 }
32 }
33 return fd;
34 }
35
36 /*
37 * Read data from a Unix fd into a pipe
38 */
39 int operator>>(int fd, Pipe& pipe)
40 {
41 secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
42 while(true)
43 {
44 ssize_t ret = read(fd, buffer.data(), buffer.size());
45 if(ret == 0) break;
46 if(ret == -1)
47 throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
48 pipe.write(buffer.data(), ret);
49 }
50 return fd;
51 }
52
53 }
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