Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
header_version.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef HEADER_VERSION_HPP
00027 #define HEADER_VERSION_HPP
00028 
00029 #include "../my_config.h"
00030 #include "infinint.hpp"
00031 #include "generic_file.hpp"
00032 #include "tools.hpp"
00033 #include "archive_version.hpp"
00034 #include "on_pool.hpp"
00035 #include "crypto.hpp"
00036 #include "slice_layout.hpp"
00037 #include "compressor.hpp"
00038 
00039 namespace libdar
00040 {
00041 
00044 
00046     class header_version : public on_pool
00047     {
00048     public:
00049     header_version();
00050     header_version(const header_version & ref) { copy_from(ref); };
00051     const header_version & operator = (const header_version & ref) { detruit(); copy_from(ref); return * this; };
00052     ~header_version() { detruit(); };
00053 
00055         void read(generic_file &f, user_interaction & dialog, bool lax_mode);
00056 
00058         void write(generic_file &f) const;
00059 
00060         // settings
00061 
00062     void set_edition(const archive_version & ed) { edition = ed; };
00063     void set_compression_algo(const compression & zip) { algo_zip = zip; };
00064     void set_command_line(const std::string & line) { cmd_line = line; };
00065     void set_initial_offset(const infinint & offset) { initial_offset = offset; };
00066     void set_sym_crypto_algo(const crypto_algo & algo) { sym = algo; };
00067 
00069     void set_crypted_key(memory_file *key) { if(key == nullptr) throw SRC_BUG; clear_crypted_key(); crypted_key = key; };
00070     void clear_crypted_key() { if(crypted_key != nullptr) { delete crypted_key; crypted_key = nullptr; } };
00071 
00073     void set_slice_layout(slice_layout *layout) { if(layout == nullptr) throw SRC_BUG; clear_slice_layout(); ref_layout = layout; };
00074     void clear_slice_layout() { if(ref_layout != nullptr) { delete ref_layout; ref_layout = nullptr; } };
00075 
00076     void set_tape_marks(bool presence) { has_tape_marks = presence; };
00077     void set_signed(bool is_signed) { arch_signed = is_signed; };
00078 
00079         // gettings
00080 
00081     const archive_version & get_edition() const { return edition; };
00082     compression get_compression_algo() const { return algo_zip; };
00083     const std::string & get_command_line() const { return cmd_line; };
00084     const infinint & get_initial_offset() const { return initial_offset; };
00085 
00086     bool is_ciphered() const { return ciphered || sym != crypto_none; };
00087     bool is_signed() const { return arch_signed; };
00088     crypto_algo get_sym_crypto_algo() const { return sym; };
00089     memory_file *get_crypted_key() const { return crypted_key; };
00090     const slice_layout *get_slice_layout() const { return ref_layout; };
00091     bool get_tape_marks() const { return has_tape_marks; };
00092 
00093     private:
00094         archive_version edition; //< archive format
00095         compression algo_zip;    //< compression algorithm used
00096         std::string cmd_line;    //< used long ago to store cmd_line, then abandonned, then recycled as a user comment field
00097     infinint initial_offset; //< defines at which offset starts the archive (passed the archive header), this field is obiously only used in the trailer not in the header
00098         // has to be set to zero when it is unknown, in that case this field is not dump to archive
00099     crypto_algo sym;         //< strong encryption algorithm used for symmetrical encryption
00100     memory_file *crypted_key;//< optional field containing the asymmetrically ciphered key used for strong encryption ciphering
00101     slice_layout *ref_layout;//< optional field used in isolated catalogues to record the slicing layout of their archive of reference
00102     bool has_tape_marks;     //< whether the archive contains tape marks aka escape marks aka sequence marks
00103 
00104     bool ciphered;   // whether the archive is ciphered, even if we do not know its crypto algorithm (old archives)
00105     bool arch_signed;     // whether the archive is signed
00106 
00107     void copy_from(const header_version & ref);
00108     void detruit();
00109 
00110         // FLAG VALUES
00111 
00112     static const U_I FLAG_SAVED_EA_ROOT = 0x80;      //< no more used since version "05"
00113     static const U_I FLAG_SAVED_EA_USER = 0x40;      //< no more used since version "05"
00114     static const U_I FLAG_SCRAMBLED     = 0x20;      //< scrambled or strong encryption used
00115     static const U_I FLAG_SEQUENCE_MARK = 0x10;      //< escape sequence marks present for sequential reading
00116     static const U_I FLAG_INITIAL_OFFSET = 0x08;     //< whether the header contains the initial offset (size of clear data before encrypted) NOTE : This value is set internally by header_version, no need to set flag with it! But that's OK to set it or not, it will be updated according to initial_offset's value.
00117     static const U_I FLAG_HAS_CRYPTED_KEY = 0x04;    //< the header contains a symmetrical key encrypted with asymmetrical algorithm
00118     static const U_I FLAG_HAS_REF_SLICING = 0x02;    //< the header contains the slicing information of the archive of reference (used for isolated catalogue)
00119     static const U_I FLAG_HAS_AN_EXTENDED_SIZE = 0x01; //< the flag is two bytes length
00120     static const U_I FLAG_ARCHIVE_IS_SIGNED = 0x0200;  //< archive is signed
00121     static const U_I FLAG_HAS_AN_SECOND_EXTENDED_SIZE = 0x0101; //< reserved for future use
00122     };
00123 
00124 } // end of namespace
00125 
00126 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines