]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/hashes.h
* apt-pkg/acquire-item.{cc,h}:
[apt.git] / apt-pkg / contrib / hashes.h
CommitLineData
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>
42ab8223
MV
23
24using std::min;
495e5cb2
MV
25using std::vector;
26
27// helper class that contains hash function name
28// and hash
29class 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
8a8feb29
MV
41 // get hash type used
42 string HashType() { return Type; };
43
495e5cb2
MV
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};
42ab8223 54
63b1700f
AL
55class Hashes
56{
57 public:
58
59 MD5Summation MD5;
60 SHA1Summation SHA1;
cde41ae8 61 SHA256Summation SHA256;
63b1700f
AL
62
63 inline bool Add(const unsigned char *Data,unsigned long Size)
64 {
cde41ae8 65 return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size);
63b1700f
AL
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