~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/lib/filters/pipe_io.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
12
namespace Botan {
 
13
 
 
14
/*
 
15
* Write data from a pipe into an ostream
 
16
*/
 
17
std::ostream& operator<<(std::ostream& stream, Pipe& pipe)
 
18
   {
 
19
   secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
 
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
*/
 
33
std::istream& operator>>(std::istream& stream, Pipe& pipe)
 
34
   {
 
35
   secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
 
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
}