Disk ARchive  2.4.12
 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; force_perm = true; 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  void set_only_hash() { only_hash = true; };
109 
110  protected:
111  U_I inherited_read(char *a, U_I size) { throw SRC_BUG; };
112  void inherited_write(const char *a, U_I size);
113  // no need to overwrite inherited_sync_write() method
114  void inherited_terminate();
115 
116  private:
117  bool only_hash; //< if set, avoids copying data to file, only compute hash (debugging purpose)
118  bool hash_ready;
119  std::string hash_filename;
120  std::string hash_extension;
121  bool force_perm;
122  U_I x_perm;
123  std::string user_ownership;
124  std::string group_ownership;
125 #if CRYPTO_AVAILABLE
126  gcry_md_hd_t hash_handle;
127 #endif
128  U_I hash_gcrypt;
129  bool eof;
130 
131 
132  void dump_hash();
133  };
134 
136 
137 } // end of namespace
138 
139 
140 #endif
class fichier definition. This is a full implementation of a generic_file applied to a plain file ...
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
gf_mode
generic_file openning modes