tronconneuse.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030
00031
00032 #ifndef TRONCONNEUSE_HPP
00033 #define TRONCONNEUSE_HPP
00034
00035 #include "../my_config.h"
00036 #include <string>
00037
00038 #include "infinint.hpp"
00039 #include "generic_file.hpp"
00040
00041 namespace libdar
00042 {
00043
00045
00058 class tronconneuse : public generic_file
00059 {
00060 public:
00062
00068 tronconneuse(user_interaction & dialog, U_32 block_size, generic_file & encrypted_side);
00069
00071 tronconneuse(const tronconneuse & ref) : generic_file(ref) { copy_from(ref); };
00072
00074 tronconneuse & operator = (const tronconneuse & ref);
00075
00077 virtual ~tronconneuse() { detruit(); };
00078
00080 bool skip(const infinint & pos);
00082 bool skip_to_eof();
00084 bool skip_relative(S_I x);
00086 infinint get_position() { return current_position; };
00087
00089
00093 void write_end_of_file() { flush(); weof = true; };
00094
00095 private:
00096
00098
00100 S_I inherited_read(char *a, size_t size);
00101
00103
00105 S_I inherited_write(const char *a, size_t size);
00106
00107 protected:
00109
00115 virtual U_32 encrypted_block_size_for(U_32 clear_block_size) = 0;
00116
00118
00125 virtual U_32 clear_block_allocated_size_for(U_32 clear_block_size) = 0;
00126
00128
00137 virtual U_32 encrypt_data(const infinint & block_num,
00138 const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated,
00139 char *crypt_buf, U_32 crypt_size) = 0;
00140
00142
00149 virtual U_32 decrypt_data(const infinint & block_num,
00150 const char *crypt_buf, const U_32 crypt_size,
00151 char *clear_buf, U_32 clear_size) = 0;
00152
00153
00154 private:
00155 infinint initial_shift;
00156 infinint buf_offset;
00157 U_32 buf_byte_data;
00158 U_32 buf_size;
00159 char *buf;
00160 U_32 clear_block_size;
00161 infinint current_position;
00162 infinint block_num;
00163 generic_file *encrypted;
00164 char *encrypted_buf;
00165 U_32 encrypted_buf_size;
00166 bool weof;
00167
00168
00169 void detruit();
00170 void copy_from(const tronconneuse & ref);
00171 U_32 fill_buf();
00172 void flush();
00173 void init_buf();
00174
00175 void position_clear2crypt(const infinint & pos, infinint & file_buf_start,
00176 infinint & clear_buf_start, infinint & pos_in_buf, infinint & block_num);
00177
00178
00179
00180
00181
00182
00183 void position_crypt2clear(const infinint & pos, infinint & clear_pos);
00184
00185
00186
00187 bool check_current_position() { return fill_buf() < buf_byte_data; };
00188
00189 };
00190
00191
00192 }
00193
00194 #endif