Disk ARchive
2.4.2
|
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 // $Id: hash_fichier.hpp,v 1.7 2011/04/17 13:12:29 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00032 00033 #ifndef HASH_FICHIER_HPP 00034 #define HASH_FICHIER_HPP 00035 00036 #include "../my_config.h" 00037 00038 extern "C" 00039 { 00040 #if HAVE_GCRYPT_H 00041 #include <gcrypt.h> 00042 #endif 00043 } 00044 00045 #include "generic_file.hpp" 00046 #include "fichier.hpp" 00047 00048 namespace libdar 00049 { 00050 00053 00054 enum hash_algo 00055 { 00056 hash_none, //< no hashing algorithm 00057 hash_md5, //< MD5 algorithm 00058 hash_sha1 //< SHA1 algorithm 00059 }; 00060 00061 00064 00065 extern std::string hash_algo_to_string(hash_algo algo); 00066 00067 class hash_fichier : public fichier 00068 { 00069 public: 00070 00071 // constructors (same as those of class fichier) 00072 00073 hash_fichier(user_interaction & dialog, S_I fd); 00074 hash_fichier(user_interaction & dialog, const char *name, gf_mode m, U_I perm, bool furtive_mode = false); 00075 hash_fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I perm, bool furtive_mode = false); 00076 hash_fichier(const std::string & chemin, bool furtive_mode = false) : fichier(chemin, furtive_mode) { throw SRC_BUG; }; 00077 hash_fichier(const hash_fichier & ref) : fichier(ref) { throw SRC_BUG; }; 00078 00079 // assignment operator 00080 const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; }; 00081 00082 // destructor 00083 ~hash_fichier(); 00084 00087 00094 void set_hash_file_name(const std::string & filename, hash_algo algo, const std::string & extension); 00095 00097 void change_permission(U_I perm) { x_perm = perm; fichier::change_permission(perm); }; 00098 void change_ownership(const std::string & user, const std::string & group) { user_ownership = user; group_ownership = group; fichier::change_ownership(user, group); }; 00099 00100 // inherited from generic_file 00101 00102 bool skip(const infinint & pos) { if(pos != fichier::get_position()) throw SRC_BUG; else return true; }; 00103 bool skip_to_eof() { throw SRC_BUG; }; 00104 bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; }; 00105 // no need to overwrite the get_position() method 00106 00107 protected: 00108 U_I inherited_read(char *a, U_I size) { throw SRC_BUG; }; 00109 void inherited_write(const char *a, U_I size); 00110 // no need to overwrite inherited_sync_write() method 00111 void inherited_terminate(); 00112 00113 private: 00114 bool hash_ready; 00115 std::string hash_filename; 00116 std::string hash_extension; 00117 U_I x_perm; 00118 std::string user_ownership; 00119 std::string group_ownership; 00120 #if CRYPTO_AVAILABLE 00121 gcry_md_hd_t hash_handle; 00122 #endif 00123 U_I hash_gcrypt; 00124 bool eof; 00125 00126 00127 void dump_hash(); 00128 }; 00129 00131 00132 } // end of namespace 00133 00134 00135 #endif