Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CIPHERSTREAM_H_
00009 #define CIPHERSTREAM_H_
00010
00011 #include "ibrcommon/Exceptions.h"
00012 #include <streambuf>
00013 #include <ostream>
00014
00015 namespace ibrcommon
00016 {
00017 class CipherStream : public std::basic_streambuf<char, std::char_traits<char> >, public std::ostream
00018 {
00019 public:
00020 enum CipherMode
00021 {
00022 CIPHER_ENCRYPT = 0,
00023 CIPHER_DECRYPT = 1
00024 };
00025
00026 CipherStream(std::ostream &stream, const CipherMode mode = CIPHER_DECRYPT, const size_t buffer = 2048);
00027 virtual ~CipherStream();
00028
00029 protected:
00030 virtual void encrypt(char *buf, const size_t size) = 0;
00031 virtual void decrypt(char *buf, const size_t size) = 0;
00032
00033 virtual int sync();
00034 virtual int overflow(int = std::char_traits<char>::eof());
00035
00036 private:
00037 std::ostream &_stream;
00038
00039 CipherMode _mode;
00040
00041
00042 char *data_buf_;
00043
00044
00045 size_t data_size_;
00046 };
00047 }
00048
00049 #endif