]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashes.h
* dpkg-triggers: Deal properly with new package states.
[apt.git] / apt-pkg / contrib / hashes.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: hashes.h,v 1.2 2001/03/11 05:30:20 jgg Exp $
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
16
17 #include <apt-pkg/md5.h>
18 #include <apt-pkg/sha1.h>
19 #include <apt-pkg/sha256.h>
20
21 #include <algorithm>
22 #include <vector>
23
24 using std::min;
25 using std::vector;
26
27 // helper class that contains hash function name
28 // and hash
29 class HashString
30 {
31 protected:
32 string Type;
33 string Hash;
34 static const char * _SupportedHashes[10];
35
36 public:
37 HashString(string Type, string Hash);
38 HashString(string StringedHashString); // init from str as "type:hash"
39 HashString();
40
41 // get hash type used
42 string HashType() { return Type; };
43
44 // verify the given filename against the currently loaded hash
45 bool VerifyFile(string filename) const;
46
47 // helper
48 string toStr() const; // convert to str as "type:hash"
49 bool empty() const;
50
51 // return the list of hashes we support
52 static const char** SupportedHashes();
53 };
54
55 class Hashes
56 {
57 public:
58
59 MD5Summation MD5;
60 SHA1Summation SHA1;
61 SHA256Summation SHA256;
62
63 inline bool Add(const unsigned char *Data,unsigned long Size)
64 {
65 return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size);
66 };
67 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
68 bool AddFD(int Fd,unsigned long Size);
69 inline bool Add(const unsigned char *Beg,const unsigned char *End)
70 {return Add(Beg,End-Beg);};
71 };
72
73 #endif