]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: sha1.h,v 1.3 2001/05/07 05:05:47 jgg Exp $ | |
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 | ||
17 | #ifdef __GNUG__ | |
18 | #pragma interface "apt-pkg/sha1.h" | |
19 | #endif | |
20 | ||
21 | #include <string> | |
22 | #include <algorithm> | |
23 | ||
24 | using std::string; | |
25 | using std::min; | |
26 | ||
27 | class SHA1Summation; | |
28 | ||
29 | class SHA1SumValue | |
30 | { | |
31 | friend class SHA1Summation; | |
32 | unsigned char Sum[20]; | |
33 | ||
34 | public: | |
35 | ||
36 | // Accessors | |
37 | bool operator ==(const SHA1SumValue &rhs) const; | |
38 | string Value() const; | |
39 | inline void Value(unsigned char S[20]) | |
40 | {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];}; | |
41 | inline operator string() const {return Value();}; | |
42 | bool Set(string Str); | |
43 | inline void Set(unsigned char S[20]) | |
44 | {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; | |
45 | ||
46 | SHA1SumValue(string Str); | |
47 | SHA1SumValue(); | |
48 | }; | |
49 | ||
50 | class SHA1Summation | |
51 | { | |
52 | /* assumes 64-bit alignment just in case */ | |
53 | unsigned char Buffer[64] __attribute__((aligned(8))); | |
54 | unsigned char State[5*4] __attribute__((aligned(8))); | |
55 | unsigned char Count[2*4] __attribute__((aligned(8))); | |
56 | bool Done; | |
57 | ||
58 | public: | |
59 | ||
60 | bool Add(const unsigned char *inbuf,unsigned long inlen); | |
61 | inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; | |
62 | bool AddFD(int Fd,unsigned long Size); | |
63 | inline bool Add(const unsigned char *Beg,const unsigned char *End) | |
64 | {return Add(Beg,End-Beg);}; | |
65 | SHA1SumValue Result(); | |
66 | ||
67 | SHA1Summation(); | |
68 | }; | |
69 | ||
70 | #endif |