| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 #ifndef GCRYPT_NO_DEPRECATED
39 #define GCRYPT_NO_DEPRECATED
40 #endif
41 #include <gcrypt.h>
42 #endif
43 }
44
45 #include <string>
46
47 #include "generic_file.hpp"
48 #include "fichier_global.hpp"
49 #include "integers.hpp"
50
51 namespace libdar
52 {
53
56
57 enum hash_algo
58 {
59 hash_none, //< no hashing algorithm
60 hash_md5, //< MD5 algorithm
61 hash_sha1, //< SHA1 algorithm
62 hash_sha512 //< SHA-512 algorithm
63 };
64
65
68
69 extern std::string hash_algo_to_string(hash_algo algo);
70
71 class hash_fichier : public fichier_global
72 {
73 public:
74
83
84 hash_fichier(user_interaction & dialog,
85 fichier_global *under,
86 const std::string & under_filename,
87 fichier_global *hash_file,
88 hash_algo algo);
89
90 // copy constructor
91 hash_fichier(const hash_fichier & ref) : fichier_global(ref) { throw SRC_BUG; };
92
93 // assignment operator
94 const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; };
95
96 // destructor
97 ~hash_fichier();
98
99 // inherited from fichier_global
100 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); };
101 void change_permission(U_I perm) { if(ref == nullptr || hash_ref == nullptr) throw SRC_BUG; ref->change_permission(perm); hash_ref->change_permission(perm); };
102 infinint get_size() const { if(ref == nullptr) throw SRC_BUG; return ref->get_size(); };
103 void fadvise(advise adv) const { if(ref == nullptr) throw SRC_BUG; ref->fadvise(adv); };
104
105 // inherited from generic_file
106 bool skippable(skippability direction, const infinint & amount) { return false; };
107 bool skip(const infinint & pos) {if(ref == nullptr || pos != ref->get_position()) throw SRC_BUG; else return true; };
108 bool skip_to_eof() { if(get_mode() == gf_write_only) return true; else throw SRC_BUG; };
109 bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; };
110 infinint get_position() const { if(ref == nullptr) throw SRC_BUG; return ref->get_position(); };
111
113 void set_only_hash() { only_hash = true; };
114
115 protected:
116 // inherited from fichier_global
117 void inherited_read_ahead(const infinint & amount) { ref->read_ahead(amount); };
118 U_I fichier_global_inherited_write(const char *a, U_I size);
119 bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message);
120
121 // inherited from generic_file
122 void inherited_sync_write() {};
123 void inherited_flush_read() {};
124 void inherited_terminate();
125
126 private:
127 fichier_global *ref;
128 fichier_global *hash_ref;
129 bool only_hash; //< if set, avoids copying data to file, only compute hash (debugging purpose)
130 #if CRYPTO_AVAILABLE
131 gcry_md_hd_t hash_handle;
132 #endif
133 std::string ref_filename;
134 U_I hash_gcrypt;
135 bool eof;
136 bool hash_dumped;
137 };
138
140
141 } // end of namespace
142
143
144 #endif
integers.hpp
are defined here basic integer types that tend to be portable
libdar::gf_write_only
write only access
Definition: generic_file.hpp:80
generic_file.hpp
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
fichier_global.hpp
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
libdar::generic_file::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition: generic_file.hpp:120
libdar::fichier_global::fichier_global
fichier_global(const user_interaction &dialog, gf_mode mode)
Definition: fichier_global.hpp:77
libdar::hash_algo
hash_algo
Definition: hash_fichier.hpp:57
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47