00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ENCRYPTSTREAMBUF_H
00016 #define ENCRYPTSTREAMBUF_H
00017
00018 #include "dtoolbase.h"
00019
00020
00021 #ifdef HAVE_OPENSSL
00022
00023 #include "openssl/evp.h"
00024
00025
00026
00027
00028
00029
00030 class EXPCL_DTOOLCONFIG EncryptStreamBuf : public streambuf {
00031 public:
00032 EncryptStreamBuf();
00033 virtual ~EncryptStreamBuf();
00034
00035 void open_read(istream *source, bool owns_source, const string &password);
00036 void close_read();
00037
00038 void open_write(ostream *dest, bool owns_dest, const string &password);
00039 void close_write();
00040
00041 INLINE void set_algorithm(const string &algorithm);
00042 INLINE const string &get_algorithm() const;
00043
00044 INLINE void set_key_length(int key_length);
00045 INLINE int get_key_length() const;
00046
00047 INLINE void set_iteration_count(int iteration_count);
00048 INLINE int get_iteration_count() const;
00049
00050 protected:
00051 virtual int overflow(int c);
00052 virtual int sync();
00053 virtual int underflow();
00054
00055 private:
00056 size_t read_chars(char *start, size_t length);
00057 void write_chars(const char *start, size_t length);
00058
00059 private:
00060 istream *_source;
00061 bool _owns_source;
00062
00063 ostream *_dest;
00064 bool _owns_dest;
00065
00066 string _algorithm;
00067 int _key_length;
00068 int _iteration_count;
00069
00070 bool _read_valid;
00071 EVP_CIPHER_CTX _read_ctx;
00072 size_t _read_block_size;
00073 unsigned char *_read_overflow_buffer;
00074 size_t _in_read_overflow_buffer;
00075
00076 bool _write_valid;
00077 EVP_CIPHER_CTX _write_ctx;
00078 size_t _write_block_size;
00079 };
00080
00081 #include "encryptStreamBuf.I"
00082
00083 #endif // HAVE_OPENSSL
00084
00085 #endif