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
00029
00030 class HashString
00031 {
00032 protected:
00033 string Type;
00034 string Hash;
00035 static const char * _SupportedHashes[10];
00036
00037 public:
00038 HashString(string Type, string Hash);
00039 HashString(string StringedHashString);
00040 HashString();
00041
00042
00043 string HashType() { return Type; };
00044
00045
00046 bool VerifyFile(string filename) const;
00047
00048
00049 string toStr() const;
00050 bool empty() const;
00051
00052
00053 static const char** SupportedHashes();
00054 };
00055
00056 class Hashes
00057 {
00058 public:
00059
00060 MD5Summation MD5;
00061 SHA1Summation SHA1;
00062 SHA256Summation SHA256;
00063
00064 inline bool Add(const unsigned char *Data,unsigned long Size)
00065 {
00066 return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size);
00067 };
00068 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
00069 bool AddFD(int Fd,unsigned long Size);
00070 inline bool Add(const unsigned char *Beg,const unsigned char *End)
00071 {return Add(Beg,End-Beg);};
00072 };
00073
00074 #endif