]>
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> | |
84a0890e | 19 | #include <apt-pkg/sha2.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; |
d9b9e9e2 | 63 | SHA512Summation SHA512; |
63b1700f AL |
64 | |
65 | inline bool Add(const unsigned char *Data,unsigned long Size) | |
66 | { | |
d9b9e9e2 | 67 | return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size); |
63b1700f AL |
68 | }; |
69 | inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; | |
1dab797c DK |
70 | inline bool AddFD(int const Fd,unsigned long Size = 0) |
71 | { return AddFD(Fd, Size, true, true, true, true); }; | |
72 | bool AddFD(int const Fd, unsigned long Size, bool const addMD5, | |
73 | bool const addSHA1, bool const addSHA256, bool const addSHA512); | |
63b1700f AL |
74 | inline bool Add(const unsigned char *Beg,const unsigned char *End) |
75 | {return Add(Beg,End-Beg);}; | |
76 | }; | |
77 | ||
78 | #endif |