]>
Commit | Line | Data |
---|---|---|
63b1700f AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
678bc33e | 3 | // $Id: hashes.h,v 1.2 2001/03/11 05:30:20 jgg Exp $ |
63b1700f AL |
4 | /* ###################################################################### |
5 | ||
6 | Hashes - Simple wrapper around the hash functions | |
7 | ||
8 | This is just used to make building the methods simpler, this is the | |
9 | only interface required.. | |
10 | ||
11 | ##################################################################### */ | |
12 | /*}}}*/ | |
13 | #ifndef APTPKG_HASHES_H | |
14 | #define APTPKG_HASHES_H | |
15 | ||
63b1700f AL |
16 | |
17 | #include <apt-pkg/md5.h> | |
18 | #include <apt-pkg/sha1.h> | |
cde41ae8 | 19 | #include <apt-pkg/sha256.h> |
63b1700f | 20 | |
42ab8223 | 21 | #include <algorithm> |
495e5cb2 | 22 | #include <vector> |
b16c2617 | 23 | #include <cstring> |
42ab8223 MV |
24 | |
25 | using std::min; | |
495e5cb2 MV |
26 | using std::vector; |
27 | ||
28 | // helper class that contains hash function name | |
29 | // and hash | |
30 | class HashString | |
31 | { | |
32 | protected: | |
33 | string Type; | |
34 | string Hash; | |
35 | static const char * _SupportedHashes[10]; | |
36 | ||
37 | public: | |
38 | HashString(string Type, string Hash); | |
39 | HashString(string StringedHashString); // init from str as "type:hash" | |
40 | HashString(); | |
41 | ||
8a8feb29 MV |
42 | // get hash type used |
43 | string HashType() { return Type; }; | |
44 | ||
495e5cb2 MV |
45 | // verify the given filename against the currently loaded hash |
46 | bool VerifyFile(string filename) const; | |
47 | ||
48 | // helper | |
49 | string toStr() const; // convert to str as "type:hash" | |
50 | bool empty() const; | |
51 | ||
52 | // return the list of hashes we support | |
53 | static const char** SupportedHashes(); | |
54 | }; | |
42ab8223 | 55 | |
63b1700f AL |
56 | class Hashes |
57 | { | |
58 | public: | |
59 | ||
60 | MD5Summation MD5; | |
61 | SHA1Summation SHA1; | |
cde41ae8 | 62 | SHA256Summation SHA256; |
63b1700f AL |
63 | |
64 | inline bool Add(const unsigned char *Data,unsigned long Size) | |
65 | { | |
cde41ae8 | 66 | return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size); |
63b1700f AL |
67 | }; |
68 | inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; | |
69 | bool AddFD(int Fd,unsigned long Size); | |
70 | inline bool Add(const unsigned char *Beg,const unsigned char *End) | |
71 | {return Add(Beg,End-Beg);}; | |
72 | }; | |
73 | ||
74 | #endif |