00001
00002
00003
00004
00005
00006
00007
00008
00009
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/sha256.h>
00020
00021 #include <algorithm>
00022 #include <vector>
00023 #include <cstring>
00024
00025 using std::min;
00026 using std::vector;
00027
00028 class FileFd;
00029
00030
00031
00032 class HashString
00033 {
00034 protected:
00035 string Type;
00036 string Hash;
00037 static const char * _SupportedHashes[10];
00038
00039 public:
00040 HashString(string Type, string Hash);
00041 HashString(string StringedHashString);
00042 HashString();
00043
00044
00045 string HashType() { return Type; };
00046
00047
00048 bool VerifyFile(string filename) const;
00049
00050
00051 string toStr() const;
00052 bool empty() const;
00053
00054
00055 static const char** SupportedHashes();
00056 };
00057
00058 class Hashes
00059 {
00060 public:
00061
00062 MD5Summation MD5;
00063 SHA1Summation SHA1;
00064 SHA256Summation SHA256;
00065
00066 inline bool Add(const unsigned char *Data,unsigned long Size)
00067 {
00068 return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size);
00069 };
00070 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
00071 bool AddFD(int Fd,unsigned long Size);
00072 inline bool AddFD(FileFd &Fd,unsigned long Size = 0)
00073 { return AddFD(Fd, Size, true, true, true, true); };
00074 bool AddFD(FileFd &Fd, unsigned long Size, bool const addMD5,
00075 bool const addSHA1, bool const addSHA256, bool const addSHA512);
00076
00077 inline bool Add(const unsigned char *Beg,const unsigned char *End)
00078 {return Add(Beg,End-Beg);};
00079 };
00080
00081 #endif