IBR-DTNSuite
0.8
|
00001 /* 00002 * InputCipherStream.h 00003 * 00004 * Created on: 13.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef INPUTCIPHERSTREAM_H_ 00009 #define INPUTCIPHERSTREAM_H_ 00010 00011 #include "ibrcommon/Exceptions.h" 00012 #include <streambuf> 00013 #include <iostream> 00014 #include <iostream> 00015 00016 namespace ibrcommon 00017 { 00018 class InputCipherStream : public std::basic_streambuf<char, std::char_traits<char> >, public std::istream 00019 { 00020 public: 00021 enum CipherMode 00022 { 00023 CIPHER_ENCRYPT = 0, 00024 CIPHER_DECRYPT = 1 00025 }; 00026 00027 InputCipherStream(std::istream &stream, const CipherMode mode = CIPHER_DECRYPT, const size_t buffer = 2048); 00028 virtual ~InputCipherStream(); 00029 00030 protected: 00031 virtual void encrypt(char *buf, const size_t size) = 0; 00032 virtual void decrypt(char *buf, const size_t size) = 0; 00033 00034 virtual int sync(); 00035 virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof()); 00036 virtual std::char_traits<char>::int_type underflow(); 00037 00038 private: 00039 std::istream &_stream; 00040 00041 CipherMode _mode; 00042 00043 // Output buffer 00044 char *data_buf_; 00045 00046 // length of the data buffer 00047 size_t data_size_; 00048 }; 00049 } 00050 00051 #endif /* INPUTCIPHERSTREAM_H_ */