Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 #include <gcrypt.h>
00039 #endif
00040 }
00041
00042 #include "generic_file.hpp"
00043 #include "fichier.hpp"
00044
00045 namespace libdar
00046 {
00047
00050
00051 enum hash_algo
00052 {
00053 hash_none,
00054 hash_md5,
00055 hash_sha1
00056 };
00057
00058
00061
00062 extern std::string hash_algo_to_string(hash_algo algo);
00063
00064 class hash_fichier : public fichier
00065 {
00066 public:
00067
00068
00069
00070 hash_fichier(user_interaction & dialog, S_I fd);
00071 hash_fichier(user_interaction & dialog, const char *name, gf_mode m, U_I perm, bool furtive_mode = false);
00072 hash_fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I perm, bool furtive_mode = false);
00073 hash_fichier(const std::string & chemin, bool furtive_mode = false) : fichier(chemin, furtive_mode) { throw SRC_BUG; };
00074 hash_fichier(const hash_fichier & ref) : fichier(ref) { throw SRC_BUG; };
00075
00076
00077 const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; };
00078
00079
00080 ~hash_fichier();
00081
00084
00091 void set_hash_file_name(const std::string & filename, hash_algo algo, const std::string & extension);
00092
00094 void change_permission(U_I perm) { x_perm = perm; fichier::change_permission(perm); };
00095 void change_ownership(const std::string & user, const std::string & group) { user_ownership = user; group_ownership = group; fichier::change_ownership(user, group); };
00096
00097
00098
00099 bool skip(const infinint & pos) { if(pos != fichier::get_position()) throw SRC_BUG; else return true; };
00100 bool skip_to_eof() { throw SRC_BUG; };
00101 bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; };
00102
00103
00104 #ifdef LIBDAR_SPECIAL_ALLOC
00105 USE_SPECIAL_ALLOC(hash_fichier);
00106 #endif
00107
00108 protected:
00109 U_I inherited_read(char *a, U_I size) { throw SRC_BUG; };
00110 void inherited_write(const char *a, U_I size);
00111
00112 void inherited_terminate();
00113
00114 private:
00115 bool hash_ready;
00116 std::string hash_filename;
00117 std::string hash_extension;
00118 U_I x_perm;
00119 std::string user_ownership;
00120 std::string group_ownership;
00121 #if CRYPTO_AVAILABLE
00122 gcry_md_hd_t hash_handle;
00123 #endif
00124 U_I hash_gcrypt;
00125 bool eof;
00126
00127
00128 void dump_hash();
00129 };
00130
00132
00133 }
00134
00135
00136 #endif