![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
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 00029 00030 #ifndef HASH_FICHIER_HPP 00031 #define HASH_FICHIER_HPP 00032 00033 #include "../my_config.h" 00034 00035 extern "C" 00036 { 00037 #if HAVE_GCRYPT_H 00038 #ifndef GCRYPT_NO_DEPRECATED 00039 #define GCRYPT_NO_DEPRECATED 00040 #endif 00041 #include <gcrypt.h> 00042 #endif 00043 } 00044 00045 #include <string> 00046 00047 #include "generic_file.hpp" 00048 #include "fichier_global.hpp" 00049 #include "integers.hpp" 00050 00051 namespace libdar 00052 { 00053 00056 00057 enum hash_algo 00058 { 00059 hash_none, //< no hashing algorithm 00060 hash_md5, //< MD5 algorithm 00061 hash_sha1, //< SHA1 algorithm 00062 hash_sha512 //< SHA-512 algorithm 00063 }; 00064 00065 00068 00069 extern std::string hash_algo_to_string(hash_algo algo); 00070 00071 class hash_fichier : public fichier_global 00072 { 00073 public: 00074 00083 00084 hash_fichier(user_interaction & dialog, 00085 fichier_global *under, 00086 const std::string & under_filename, 00087 fichier_global *hash_file, 00088 hash_algo algo); 00089 00090 // copy constructor 00091 hash_fichier(const hash_fichier & ref) : fichier_global(ref) { throw SRC_BUG; }; 00092 00093 // assignment operator 00094 const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; }; 00095 00096 // destructor 00097 ~hash_fichier(); 00098 00099 // inherited from fichier_global 00100 void change_ownership(const std::string & user, const std::string & group) { if(ref == nullptr || hash_ref == nullptr) throw SRC_BUG; ref->change_ownership(user, group); hash_ref->change_ownership(user, group); }; 00101 void change_permission(U_I perm) { if(ref == nullptr || hash_ref == nullptr) throw SRC_BUG; ref->change_permission(perm); hash_ref->change_permission(perm); }; 00102 infinint get_size() const { if(ref == nullptr) throw SRC_BUG; return ref->get_size(); }; 00103 void fadvise(advise adv) const { if(ref == nullptr) throw SRC_BUG; ref->fadvise(adv); }; 00104 00105 // inherited from generic_file 00106 bool skippable(skippability direction, const infinint & amount) { return false; }; 00107 bool skip(const infinint & pos) {if(ref == nullptr || pos != ref->get_position()) throw SRC_BUG; else return true; }; 00108 bool skip_to_eof() { if(get_mode() == gf_write_only) return true; else throw SRC_BUG; }; 00109 bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; }; 00110 infinint get_position() const { if(ref == nullptr) throw SRC_BUG; return ref->get_position(); }; 00111 00113 void set_only_hash() { only_hash = true; }; 00114 00115 protected: 00116 // inherited from fichier_global 00117 void inherited_read_ahead(const infinint & amount) { ref->read_ahead(amount); }; 00118 U_I fichier_global_inherited_write(const char *a, U_I size); 00119 bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message); 00120 00121 // inherited from generic_file 00122 void inherited_sync_write() {}; 00123 void inherited_flush_read() {}; 00124 void inherited_terminate(); 00125 00126 private: 00127 fichier_global *ref; 00128 fichier_global *hash_ref; 00129 bool only_hash; //< if set, avoids copying data to file, only compute hash (debugging purpose) 00130 #if CRYPTO_AVAILABLE 00131 gcry_md_hd_t hash_handle; 00132 #endif 00133 std::string ref_filename; 00134 U_I hash_gcrypt; 00135 bool eof; 00136 bool hash_dumped; 00137 }; 00138 00140 00141 } // end of namespace 00142 00143 00144 #endif