Disk ARchive  2.4.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
hash_fichier.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
29 
30 #ifndef HASH_FICHIER_HPP
31 #define HASH_FICHIER_HPP
32 
33 #include "../my_config.h"
34 
35 extern "C"
36 {
37 #if HAVE_GCRYPT_H
38 #include <gcrypt.h>
39 #endif
40 }
41 
42 #include "generic_file.hpp"
43 #include "fichier.hpp"
44 
45 namespace libdar
46 {
47 
50 
51  enum hash_algo
52  {
53  hash_none, //< no hashing algorithm
54  hash_md5, //< MD5 algorithm
55  hash_sha1 //< SHA1 algorithm
56  };
57 
58 
61 
62  extern std::string hash_algo_to_string(hash_algo algo);
63 
64  class hash_fichier : public fichier
65  {
66  public:
67 
68  // constructors (same as those of class fichier)
69 
70  hash_fichier(user_interaction & dialog, S_I fd);
71  hash_fichier(user_interaction & dialog, const char *name, gf_mode m, U_I perm, bool furtive_mode = false);
72  hash_fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I perm, bool furtive_mode = false);
73  hash_fichier(const std::string & chemin, bool furtive_mode = false) : fichier(chemin, furtive_mode) { throw SRC_BUG; };
74  hash_fichier(const hash_fichier & ref) : fichier(ref) { throw SRC_BUG; };
75 
76  // assignment operator
77  const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; };
78 
79  // destructor
80  ~hash_fichier();
81 
84 
91  void set_hash_file_name(const std::string & filename, hash_algo algo, const std::string & extension);
92 
94  void change_permission(U_I perm) { x_perm = perm; fichier::change_permission(perm); };
95  void change_ownership(const std::string & user, const std::string & group) { user_ownership = user; group_ownership = group; fichier::change_ownership(user, group); };
96 
97  // inherited from generic_file
98 
99  bool skip(const infinint & pos) { if(pos != fichier::get_position()) throw SRC_BUG; else return true; };
100  bool skip_to_eof() { throw SRC_BUG; };
101  bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; };
102  // no need to overwrite the get_position() method
103 
104 #ifdef LIBDAR_SPECIAL_ALLOC
105  USE_SPECIAL_ALLOC(hash_fichier);
106 #endif
107 
108  protected:
109  U_I inherited_read(char *a, U_I size) { throw SRC_BUG; };
110  void inherited_write(const char *a, U_I size);
111  // no need to overwrite inherited_sync_write() method
112  void inherited_terminate();
113 
114  private:
115  bool hash_ready;
116  std::string hash_filename;
117  std::string hash_extension;
118  U_I x_perm;
119  std::string user_ownership;
120  std::string group_ownership;
121 #if CRYPTO_AVAILABLE
122  gcry_md_hd_t hash_handle;
123 #endif
124  U_I hash_gcrypt;
125  bool eof;
126 
127 
128  void dump_hash();
129  };
130 
132 
133 } // end of namespace
134 
135 
136 #endif