]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/md5.h
Clean support
[apt.git] / apt-pkg / contrib / md5.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: md5.h,v 1.3 1999/01/18 06:20:08 jgg Exp $
4 /* ######################################################################
5
6 MD5SumValue - Storage for a MD5Sum
7 MD5Summation - MD5 Message Digest Algorithm.
8
9 This is a C++ interface to a set of MD5Sum functions. The class can
10 store a MD5Sum in 16 bytes of memory.
11
12 A MD5Sum is used to generate a (hopefully) unique 16 byte number for a
13 block of data. This can be used to gaurd against corruption of a file.
14
15 There are two classes because computing a MD5 is not a continual
16 operation unless 64 byte blocks are used. Also the summation requires an
17 extra 18*4 bytes to operate.
18
19 ##################################################################### */
20 /*}}}*/
21 #ifndef APTPKG_MD5_H
22 #define APTPKG_MD5_H
23
24 #ifdef __GNUG__
25 #pragma interface "apt-pkg/md5.h"
26 #endif
27
28 #include <string>
29
30 class MD5Summation;
31
32 class MD5SumValue
33 {
34 friend MD5Summation;
35 unsigned char Sum[4*4];
36
37 public:
38
39 // Accessors
40 bool operator ==(const MD5SumValue &rhs) const;
41 string Value() const;
42 inline void Value(unsigned char S[16])
43 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
44 inline operator string() const {return Value();};
45 bool Set(string Str);
46 inline void Set(unsigned char S[16])
47 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
48
49 MD5SumValue(string Str);
50 MD5SumValue();
51 };
52
53 class MD5Summation
54 {
55 unsigned char Buf[4*4];
56 unsigned char Bytes[2*4];
57 unsigned char In[16*4];
58 bool Done;
59
60 public:
61
62 bool Add(const unsigned char *Data,unsigned long Size);
63 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
64 bool AddFD(int Fd,unsigned long Size);
65 inline bool Add(const unsigned char *Beg,const unsigned char *End)
66 {return Add(Beg,End-Beg);};
67 MD5SumValue Result();
68
69 MD5Summation();
70 };
71
72 #endif