IBR-DTNSuite
0.8
|
00001 /* 00002 * InputCipherStream.cpp 00003 * 00004 * Created on: 13.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #include "ibrcommon/ssl/InputCipherStream.h" 00009 00010 namespace ibrcommon 00011 { 00012 InputCipherStream::InputCipherStream(std::istream &stream, const CipherMode mode, const size_t buffer) 00013 : std::istream(this), _stream(stream), _mode(mode), data_buf_(new char[buffer]), read_buf_(new char[buffer]), data_size_(buffer) 00014 { 00015 // Initialize get pointer. This should be zero so that underflow is called upon first read. 00016 setg(0, 0, 0); 00017 setp(data_buf_, data_buf_ + data_size_ - 1); 00018 } 00019 00020 InputCipherStream::~InputCipherStream() 00021 { 00022 delete[] data_buf_; 00023 } 00024 00025 std::char_traits<char>::int_type InputCipherStream::underflow() 00026 { 00027 _stream.read(data_buf_, data_size_); 00028 int bytes = _stream.gcount(); 00029 00030 if (bytes == 0) 00031 { 00032 return std::char_traits<char>::eof(); 00033 } 00034 00035 // Since the input buffer content is now valid (or is new) 00036 // the get pointer should be initialized (or reset). 00037 setg(data_buf_, data_buf_, data_buf_ + bytes); 00038 00039 return std::char_traits<char>::not_eof((unsigned char) data_buf_[0]); 00040 } 00041 }