]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/sha1.h
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / contrib / sha1.h
CommitLineData
784202a2
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
233b185f 3// $Id: sha1.h,v 1.3 2001/05/07 05:05:47 jgg Exp $
784202a2
AL
4/* ######################################################################
5
6 SHA1SumValue - Storage for a SHA-1 hash.
7 SHA1Summation - SHA-1 Secure Hash Algorithm.
8
9 This is a C++ interface to a set of SHA1Sum functions, that mirrors
10 the equivalent MD5 classes.
11
12 ##################################################################### */
13 /*}}}*/
14#ifndef APTPKG_SHA1_H
15#define APTPKG_SHA1_H
16
784202a2 17#include <string>
42ab8223 18#include <algorithm>
784202a2 19
233b185f 20using std::string;
42ab8223 21using std::min;
233b185f 22
784202a2
AL
23class SHA1Summation;
24
25class SHA1SumValue
26{
27 friend class SHA1Summation;
28 unsigned char Sum[20];
29
30 public:
31
32 // Accessors
33 bool operator ==(const SHA1SumValue &rhs) const;
34 string Value() const;
35 inline void Value(unsigned char S[20])
36 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
37 inline operator string() const {return Value();};
38 bool Set(string Str);
39 inline void Set(unsigned char S[20])
40 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
41
42 SHA1SumValue(string Str);
43 SHA1SumValue();
44};
45
46class SHA1Summation
47{
70949daf
AL
48 /* assumes 64-bit alignment just in case */
49 unsigned char Buffer[64] __attribute__((aligned(8)));
50 unsigned char State[5*4] __attribute__((aligned(8)));
51 unsigned char Count[2*4] __attribute__((aligned(8)));
784202a2
AL
52 bool Done;
53
54 public:
55
56 bool Add(const unsigned char *inbuf,unsigned long inlen);
57 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
58 bool AddFD(int Fd,unsigned long Size);
59 inline bool Add(const unsigned char *Beg,const unsigned char *End)
60 {return Add(Beg,End-Beg);};
61 SHA1SumValue Result();
62
63 SHA1Summation();
64};
65
66#endif