]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/md5.h
* merged the fixes from apt--progress-reporting
[apt.git] / apt-pkg / contrib / md5.h
CommitLineData
17a10bf5
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
233b185f 3// $Id: md5.h,v 1.6 2001/05/07 05:06:52 jgg Exp $
17a10bf5
AL
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.
6e52073f
AL
14 MD5 should not be used for tamper protection, use SHA or something more
15 secure.
17a10bf5
AL
16
17 There are two classes because computing a MD5 is not a continual
18 operation unless 64 byte blocks are used. Also the summation requires an
19 extra 18*4 bytes to operate.
20
21 ##################################################################### */
22 /*}}}*/
23#ifndef APTPKG_MD5_H
24#define APTPKG_MD5_H
25
26#ifdef __GNUG__
27#pragma interface "apt-pkg/md5.h"
28#endif
29
30#include <string>
8bdbcf67 31#include <algorithm>
17a10bf5 32
233b185f 33using std::string;
8bdbcf67 34using std::min;
233b185f 35
17a10bf5
AL
36class MD5Summation;
37
38class MD5SumValue
39{
b2e465d6 40 friend class MD5Summation;
17a10bf5
AL
41 unsigned char Sum[4*4];
42
43 public:
44
45 // Accessors
46 bool operator ==(const MD5SumValue &rhs) const;
47 string Value() const;
7f25bdff
AL
48 inline void Value(unsigned char S[16])
49 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
50 inline operator string() const {return Value();};
17a10bf5 51 bool Set(string Str);
7f25bdff
AL
52 inline void Set(unsigned char S[16])
53 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
54
17a10bf5
AL
55 MD5SumValue(string Str);
56 MD5SumValue();
57};
58
59class MD5Summation
60{
61 unsigned char Buf[4*4];
62 unsigned char Bytes[2*4];
63 unsigned char In[16*4];
64 bool Done;
65
66 public:
67
68 bool Add(const unsigned char *Data,unsigned long Size);
bc4af0b9 69 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
17a10bf5
AL
70 bool AddFD(int Fd,unsigned long Size);
71 inline bool Add(const unsigned char *Beg,const unsigned char *End)
72 {return Add(Beg,End-Beg);};
73 MD5SumValue Result();
74
75 MD5Summation();
76};
77
78#endif