Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
tronconneuse.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
27
28#ifndef TRONCONNEUSE_HPP
29#define TRONCONNEUSE_HPP
30
31#include "../my_config.h"
32#include <string>
33
34#include "infinint.hpp"
35#include "archive_version.hpp"
36#include "crypto_module.hpp"
37#include "proto_tronco.hpp"
38
39namespace libdar
40{
41
44
45
47
53 class tronconneuse : public proto_tronco
54 {
55 public:
57
64 tronconneuse(U_32 block_size,
65 generic_file & encrypted_side,
67 std::unique_ptr<crypto_module> & ptr);
68
70 tronconneuse(const tronconneuse & ref) : proto_tronco(ref) { copy_from(ref); };
71
73 tronconneuse(tronconneuse && ref) noexcept: proto_tronco(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
74
76 tronconneuse & operator = (const tronconneuse & ref) { detruit(); proto_tronco::operator = (ref); copy_from(ref); return *this; };
77
79 tronconneuse & operator = (tronconneuse && ref) noexcept { proto_tronco::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
80
82 virtual ~tronconneuse() noexcept override { detruit(); }; // must not write pure virtual method from here, directly or not
83
85 virtual bool skippable(skippability direction, const infinint & amount) override;
87 virtual bool skip(const infinint & pos) override;
89 virtual bool skip_to_eof() override;
91 virtual bool skip_relative(S_I x) override;
93 virtual bool truncatable(const infinint & pos) const override { return false; };
95 virtual infinint get_position() const override { if(is_terminated()) throw SRC_BUG; return current_position; };
96
98
103 virtual void write_end_of_file() override { if(is_terminated()) throw SRC_BUG; flush(); weof = true; };
104
105
107
108 virtual void set_initial_shift(const infinint & x) override { initial_shift = x; };
109
114
116 virtual U_32 get_clear_block_size() const override { return clear_block_size; };
117
118 private:
119
121
123 virtual void inherited_read_ahead(const infinint & amount) override;
124
126 virtual U_I inherited_read(char *a, U_I size) override;
127
129
131 virtual void inherited_write(const char *a, U_I size) override;
132
134 virtual void inherited_truncate(const infinint & pos) override { throw SRC_BUG; }; // no skippability in write mode, so no truncate possibility neither
135
137 virtual void inherited_sync_write() override { flush(); };
138
139
141 virtual void inherited_flush_read() override { buf_byte_data = 0; };
142
144 virtual void inherited_terminate() override { flush(); };
145
146 protected:
147 const archive_version & get_reading_version() const { return reading_ver; };
148
149
150 private:
152 //
155 U_32 buf_size;
156 char *buf;
157 //
162 //
166 //
170 char *extra_buf;
171 //
172 bool weof;
173 bool reof;
175 std::unique_ptr<crypto_module> crypto;
177
178
179 void nullifyptr() noexcept;
180 void detruit() noexcept;
181 void copy_from(const tronconneuse & ref);
182 void move_from(tronconneuse && ref) noexcept;
183 U_32 fill_buf();
184 void flush();
185 void init_buf();
186
187
189
196 infinint & file_buf_start,
197 infinint & clear_buf_start,
198 infinint & pos_in_buf,
200
203 void position_crypt2clear(const infinint & pos, infinint & clear_pos);
204
207
212
213 };
214
216
217} // end of namespace
218
219#endif
class archive_version that rules which archive format to follow
class archive_version manages the version of the archive format
this is the interface class from which all other data transfer classes inherit
generic_file & operator=(const generic_file &ref)
assignment operator
bool is_terminated() const
the arbitrary large positive integer class
this is a partial implementation of the generic_file interface to cypher/decypher data block by block...
virtual U_I inherited_read(char *a, U_I size) override
this protected inherited method is now private for inherited classes of tronconneuse
virtual ~tronconneuse() noexcept override
destructor
virtual bool skip_to_eof() override
inherited from generic_file
virtual void set_initial_shift(const infinint &x) override
this method to modify the initial shift. This overrides the constructor "no_initial_shift" of the con...
tronconneuse(const tronconneuse &ref)
copy constructor
U_32 buf_size
size of allocated memory for clear data in buf
generic_file * encrypted
generic_file where is put / get the encrypted data
infinint current_position
position of the next character to read or write from the upper layer perspective, offset zero is the ...
infinint buf_offset
offset of the first byte in buf
tronconneuse & operator=(const tronconneuse &ref)
assignment operator
char * encrypted_buf
buffer of encrypted data (read or to write)
std::unique_ptr< crypto_module > crypto
wraps the per block encryption/decryption routines
U_32 extra_buf_data
amount of byte of information in extra_buf
char * buf
decrypted data (or data to encrypt)
virtual void inherited_truncate(const infinint &pos) override
this prorected inherited method is now private for inherited classed of tronconneuse
U_32 encrypted_buf_size
allocated size of encrypted_buf
virtual void inherited_read_ahead(const infinint &amount) override
inherited from generic_file
void position_clear2crypt(const infinint &pos, infinint &file_buf_start, infinint &clear_buf_start, infinint &pos_in_buf, infinint &block_num)
convert clear position to corresponding position in the encrypted data
infinint initial_shift
the initial_shift first bytes of the underlying file are not encrypted
void flush()
flush any pending data (write mode only) to encrypted device
char * extra_buf
additional read encrypted that follow what is in encrypted_buf used to check for clear data after enc...
virtual void inherited_terminate() override
this protected inherited method is now private for inherited classes of tronconneuse
infinint block_num
block number we next read or write
virtual void write_end_of_file() override
in write_only mode indicate that end of file is reached
U_32 fill_buf()
returns the position (of the next read op) inside the buffer and fill the buffer with clear data
trailing_clear_data_callback trailing_clear_data
callback function that gives the amount of clear data found at the end of the given file
infinint extra_buf_offset
offset of the first byte of extra_buf
tronconneuse(tronconneuse &&ref) noexcept
move constructor
bool reof
whether we reached eof while reading
virtual bool skippable(skippability direction, const infinint &amount) override
inherited from generic_file
bool weof
whether write_end_of_file() has been called
virtual bool skip_relative(S_I x) override
inherited from generic_file
virtual void inherited_flush_read() override
this protected inherited method is now private for inherited classes of tronconneuse
virtual U_32 get_clear_block_size() const override
returns the block size give to constructor
U_32 encrypted_buf_data
amount of byte of information in encrypted_buf
U_32 clear_block_size
max amount of data that will be encrypted at once (must stay less than buf_size)
archive_version reading_ver
archive format we currently read
virtual infinint get_position() const override
inherited from generic_file
void remove_trailing_clear_data_from_encrypted_buf(const infinint &crypt_offset)
bool check_current_position()
return true if a there is a byte of information at the given offset
virtual bool skip(const infinint &pos) override
inherited from generic_file
void init_buf()
initialize if necessary the various buffers that relies on inherited method values
virtual void inherited_write(const char *a, U_I size) override
inherited from generic_file
U_32 extra_buf_size
allocated size of extra_buf
tronconneuse(U_32 block_size, generic_file &encrypted_side, const archive_version &reading_ver, std::unique_ptr< crypto_module > &ptr)
This is the constructor.
U_32 buf_byte_data
number of byte of information in buf (buf_byte_data <= buf_size)
virtual bool truncatable(const infinint &pos) const override
inherited from generic_file
virtual void set_callback_trailing_clear_data(trailing_clear_data_callback callback) override
virtual void inherited_sync_write() override
this protected inherited method is now private for inherited classes of tronconneuse
void position_crypt2clear(const infinint &pos, infinint &clear_pos)
per block cryptography implementation
infinint(* trailing_clear_data_callback)(generic_file &below, const archive_version &reading_ver)
the trailing_clear_data_callback call back is a mean by which the upper layer cat tell when encrypted...
switch module to limitint (32 ou 64 bits integers) or infinint
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
defines common interface for tronconneuse and parallel_tronconneuse