|
apt @VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: hashes.h,v 1.2 2001/03/11 05:30:20 jgg Exp $ 00004 /* ###################################################################### 00005 00006 Hashes - Simple wrapper around the hash functions 00007 00008 This is just used to make building the methods simpler, this is the 00009 only interface required.. 00010 00011 ##################################################################### */ 00012 /*}}}*/ 00013 #ifndef APTPKG_HASHES_H 00014 #define APTPKG_HASHES_H 00015 00016 00017 #include <apt-pkg/md5.h> 00018 #include <apt-pkg/sha1.h> 00019 #include <apt-pkg/sha2.h> 00020 00021 #include <algorithm> 00022 #include <vector> 00023 #include <cstring> 00024 00025 // helper class that contains hash function name 00026 // and hash 00027 class HashString 00028 { 00029 protected: 00030 std::string Type; 00031 std::string Hash; 00032 static const char * _SupportedHashes[10]; 00033 00034 public: 00035 HashString(std::string Type, std::string Hash); 00036 HashString(std::string StringedHashString); // init from str as "type:hash" 00037 HashString(); 00038 00039 // get hash type used 00040 std::string HashType() { return Type; }; 00041 00042 // verify the given filename against the currently loaded hash 00043 bool VerifyFile(std::string filename) const; 00044 00045 // helper 00046 std::string toStr() const; // convert to str as "type:hash" 00047 bool empty() const; 00048 00049 // return the list of hashes we support 00050 static const char** SupportedHashes(); 00051 }; 00052 00053 class Hashes 00054 { 00055 public: 00056 00057 MD5Summation MD5; 00058 SHA1Summation SHA1; 00059 SHA256Summation SHA256; 00060 SHA512Summation SHA512; 00061 00062 inline bool Add(const unsigned char *Data,unsigned long long Size) 00063 { 00064 return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size); 00065 }; 00066 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; 00067 inline bool AddFD(int const Fd,unsigned long long Size = 0) 00068 { return AddFD(Fd, Size, true, true, true, true); }; 00069 bool AddFD(int const Fd, unsigned long long Size, bool const addMD5, 00070 bool const addSHA1, bool const addSHA256, bool const addSHA512); 00071 inline bool Add(const unsigned char *Beg,const unsigned char *End) 00072 {return Add(Beg,End-Beg);}; 00073 }; 00074 00075 #endif
1.7.4