| Disk ARchive 2.6.12 Full featured and portable backup and archiving tool

header_version.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2020 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 : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26 #ifndef HEADER_VERSION_HPP
27 #define HEADER_VERSION_HPP
28
29 #include "../my_config.h"
30 #include "infinint.hpp"
31 #include "generic_file.hpp"
32 #include "archive_version.hpp"
33 #include "crypto.hpp"
34 #include "slice_layout.hpp"
35 #include "compression.hpp"
36 #include "user_interaction.hpp"
37 #include "memory_file.hpp"
38 #include "archive_aux.hpp"
39
40 namespace libdar
41 {
42
45
47 class header_version
48 {
49 public:
50 header_version();
51 header_version(const header_version & ref) { copy_from(ref); };
52 header_version(header_version && ref) noexcept { nullifyptr(); move_from(std::move(ref)); };
53 header_version & operator = (const header_version & ref) { detruit(); copy_from(ref); return * this; };
54 header_version & operator = (header_version && ref) noexcept { move_from(std::move(ref)); return *this; };
55 ~header_version() { detruit(); };
56
58 void read(generic_file &f, user_interaction & dialog, bool lax_mode);
59
61 void write(generic_file &f) const;
62
63 // settings
64
65 void set_edition(const archive_version & ed) { edition = ed; };
66 void set_compression_algo(const compression & zip) { algo_zip = zip; };
67 void set_command_line(const std::string & line) { cmd_line = line; };
68 void set_initial_offset(const infinint & offset) { initial_offset = offset; };
69 void set_sym_crypto_algo(const crypto_algo & algo) { sym = algo; };
70
72 void set_crypted_key(memory_file *key) { if(key == nullptr) throw SRC_BUG; clear_crypted_key(); crypted_key = key; };
73 void clear_crypted_key() { if(crypted_key != nullptr) { delete crypted_key; crypted_key = nullptr; } };
74
76 void set_slice_layout(slice_layout *layout) { if(layout == nullptr) throw SRC_BUG; clear_slice_layout(); ref_layout = layout; };
77 void clear_slice_layout() { if(ref_layout != nullptr) { delete ref_layout; ref_layout = nullptr; } };
78
79 void set_tape_marks(bool presence) { has_tape_marks = presence; };
80 void set_signed(bool is_signed) { arch_signed = is_signed; };
81
82 void set_salt(const std::string & arg) { salt = arg; };
83 void set_iteration_count(const infinint & arg) { iteration_count = arg; };
84 void set_kdf_hash(hash_algo algo);
85
86 // gettings
87
88 const archive_version & get_edition() const { return edition; };
89 compression get_compression_algo() const { return algo_zip; };
90 const std::string & get_command_line() const { return cmd_line; };
91 const infinint & get_initial_offset() const { return initial_offset; };
92
93 bool is_ciphered() const { return ciphered || sym != crypto_algo::none; };
94 bool is_signed() const { return arch_signed; };
95 crypto_algo get_sym_crypto_algo() const { return sym; };
96 std::string get_sym_crypto_name() const;
97 std::string get_asym_crypto_name() const;
98 memory_file *get_crypted_key() const { return crypted_key; };
99 const slice_layout *get_slice_layout() const { return ref_layout; };
100 bool get_tape_marks() const { return has_tape_marks; };
101 const std::string & get_salt() const { return salt; };
102 const infinint & get_iteration_count() const { return iteration_count; };
103 hash_algo get_kdf_hash() const { return kdf_hash; };
104
105 // display
106
107 void display(user_interaction & dialg) const;
108
109 // clear
110
111 void clear();
112
113 private:
114 archive_version edition;
115 compression algo_zip;
116 std::string cmd_line;
117 infinint initial_offset;
118 // has to be set to zero when it is unknown, in that case this field is not dump to archive
119 crypto_algo sym;
120 memory_file *crypted_key;
121 slice_layout *ref_layout;
122 bool has_tape_marks;
123
124 bool ciphered;
125 bool arch_signed;
126 std::string salt;
127 infinint iteration_count;
128 hash_algo kdf_hash;
129
130 void nullifyptr() noexcept { crypted_key = nullptr; ref_layout = nullptr; };
131 void copy_from(const header_version & ref);
132 void move_from(header_version && ref) noexcept;
133 void detruit();
134
135 // FLAG VALUES
136
137 // flags of the historical bytes (oldest), read/wrote last (or alone if no extra bits are set)
138 static constexpr U_I FLAG_SAVED_EA_ROOT = 0x80;
139 static constexpr U_I FLAG_SAVED_EA_USER = 0x40;
140 static constexpr U_I FLAG_SCRAMBLED = 0x20;
141 static constexpr U_I FLAG_SEQUENCE_MARK = 0x10;
142 static constexpr U_I FLAG_INITIAL_OFFSET = 0x08;
143 static constexpr U_I FLAG_HAS_CRYPTED_KEY = 0x04;
144 static constexpr U_I FLAG_HAS_REF_SLICING = 0x02;
145
146 // if flag is two bytes long, the first byte read/wrote has this bit set
147 static constexpr U_I FLAG_HAS_AN_EXTENDED_SIZE = 0x01;
148
149 // flags of the new byte (read/wrote before the historical byte)
150 static constexpr U_I FLAG_ARCHIVE_IS_SIGNED = 0x0200;
151 static constexpr U_I FLAG_HAS_KDF_PARAM = 0x0400;
152
153 // if the flag is three or more bytes long, these bits are set in the first and second bytes
154 static constexpr U_I FLAG_HAS_AN_SECOND_EXTENDED_SIZE = 0x0101;
155
156 //
157
158 static constexpr U_I PRE_FORMAT_10_ITERATION = 2000;
159
160 // check we are not facing a more recent format than what we know, this would fail CRC calculation before reporting the real reason of the issue
161 static bool all_flags_known(U_I flag);
162
163 };
164
165 } // end of namespace
166
167 #endif
libdar::header_version::FLAG_HAS_AN_EXTENDED_SIZE
static constexpr U_I FLAG_HAS_AN_EXTENDED_SIZE
the flag is two bytes length
Definition: header_version.hpp:147
libdar::hash_algo
hash_algo
hashing algorithm available
Definition: archive_aux.hpp:63
libdar::header_version::FLAG_HAS_CRYPTED_KEY
static constexpr U_I FLAG_HAS_CRYPTED_KEY
the header contains a symmetrical key encrypted with asymmetrical algorithm
Definition: header_version.hpp:143
libdar::compression
compression
the different compression algorithm available
Definition: compression.hpp:46
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition: user_interaction.hpp:47
libdar::header_version::FLAG_HAS_AN_SECOND_EXTENDED_SIZE
static constexpr U_I FLAG_HAS_AN_SECOND_EXTENDED_SIZE
reserved for future use
Definition: header_version.hpp:154
libdar::header_version::FLAG_ARCHIVE_IS_SIGNED
static constexpr U_I FLAG_ARCHIVE_IS_SIGNED
archive is signed
Definition: header_version.hpp:150
compression.hpp
compression parameters for API
user_interaction.hpp
defines the interaction interface between libdar and users.
libdar::header_version::cmd_line
std::string cmd_line
used long ago to store cmd_line, then abandonned, then recycled as a user comment field
Definition: header_version.hpp:116
libdar::header_version::FLAG_INITIAL_OFFSET
static constexpr U_I FLAG_INITIAL_OFFSET
whether the header contains the initial offset (size of clear data before encrypted) NOTE : This valu...
Definition: header_version.hpp:142
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::header_version::ciphered
bool ciphered
whether the archive is ciphered, even if we do not know its crypto algorithm (old archives)
Definition: header_version.hpp:124
archive_version.hpp
class archive_version that rules which archive format to follow
libdar::header_version::salt
std::string salt
used for key derivation
Definition: header_version.hpp:126
libdar::header_version::edition
archive_version edition
archive format
Definition: header_version.hpp:114
libdar::header_version::FLAG_SAVED_EA_ROOT
static constexpr U_I FLAG_SAVED_EA_ROOT
no more used since version "05"
Definition: header_version.hpp:138
libdar::archive_version
class archive_version manages the version of the archive format
Definition: archive_version.hpp:47
libdar::crypto_algo::none
@ none
no encryption
libdar::header_version::ref_layout
slice_layout * ref_layout
optional field used in isolated catalogues to record the slicing layout of their archive of reference
Definition: header_version.hpp:121
libdar::header_version::set_crypted_key
void set_crypted_key(memory_file *key)
the object pointed to by key passes to the responsibility of this header_version object
Definition: header_version.hpp:72
libdar::header_version::arch_signed
bool arch_signed
whether the archive is signed
Definition: header_version.hpp:125
libdar::header_version::write
void write(generic_file &f) const
write down the object to the archive (as header if wrote at the beginning of the archive,...
libdar::header_version::FLAG_SAVED_EA_USER
static constexpr U_I FLAG_SAVED_EA_USER
no more used since version "05"
Definition: header_version.hpp:139
libdar::header_version::algo_zip
compression algo_zip
compression algorithm used
Definition: header_version.hpp:115
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::header_version::FLAG_SCRAMBLED
static constexpr U_I FLAG_SCRAMBLED
scrambled or strong encryption used
Definition: header_version.hpp:140
libdar::header_version::crypted_key
memory_file * crypted_key
optional field containing the asymmetrically ciphered key used for strong encryption ciphering
Definition: header_version.hpp:120
slice_layout.hpp
object describing the slicing of an archive
libdar::header_version::FLAG_HAS_KDF_PARAM
static constexpr U_I FLAG_HAS_KDF_PARAM
archive header contains salt and non default interaction count
Definition: header_version.hpp:151
libdar::header_version::initial_offset
infinint initial_offset
defines at which offset starts the archive (passed the archive header), this field is obiously only u...
Definition: header_version.hpp:117
archive_aux.hpp
set of datastructures used to interact with a catalogue object
memory_file.hpp
Memory_file is a generic_file class that only uses virtual memory.
libdar::header_version::FLAG_SEQUENCE_MARK
static constexpr U_I FLAG_SEQUENCE_MARK
escape sequence marks present for sequential reading
Definition: header_version.hpp:141
libdar::memory_file
generic_file stored in memory
Definition: memory_file.hpp:41
libdar::header_version::kdf_hash
hash_algo kdf_hash
used for key derivation
Definition: header_version.hpp:128
libdar::header_version::FLAG_HAS_REF_SLICING
static constexpr U_I FLAG_HAS_REF_SLICING
the header contains the slicing information of the archive of reference (used for isolated catalogue)
Definition: header_version.hpp:144
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::header_version::has_tape_marks
bool has_tape_marks
whether the archive contains tape marks aka escape marks aka sequence marks
Definition: header_version.hpp:122
libdar::header_version::iteration_count
infinint iteration_count
used for key derivation
Definition: header_version.hpp:127
libdar::header_version::PRE_FORMAT_10_ITERATION
static constexpr U_I PRE_FORMAT_10_ITERATION
fixed value used for key derivation before archive format 10
Definition: header_version.hpp:158
libdar::header_version::set_slice_layout
void set_slice_layout(slice_layout *layout)
the object pointed to by layout is passed under the responsibility of this header_version object
Definition: header_version.hpp:76
libdar::crypto_algo
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:50
libdar::header_version::sym
crypto_algo sym
strong encryption algorithm used for symmetrical encryption
Definition: header_version.hpp:119
libdar::header_version
manages the archive header and trailer
Definition: header_version.hpp:48
crypto.hpp
the crypto algoritm definition
libdar::header_version::read
void read(generic_file &f, user_interaction &dialog, bool lax_mode)
read the header or trailer from the archive
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47