00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef APTPKG_SHA1_H
00015 #define APTPKG_SHA1_H
00016
00017 #include <string>
00018 #include <cstring>
00019 #include <algorithm>
00020
00021 using std::string;
00022 using std::min;
00023
00024 class SHA1Summation;
00025
00026 class SHA1SumValue
00027 {
00028 friend class SHA1Summation;
00029 unsigned char Sum[20];
00030
00031 public:
00032
00033
00034 bool operator ==(const SHA1SumValue &rhs) const;
00035 string Value() const;
00036 inline void Value(unsigned char S[20])
00037 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
00038 inline operator string() const {return Value();};
00039 bool Set(string Str);
00040 inline void Set(unsigned char S[20])
00041 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
00042
00043 SHA1SumValue(string Str);
00044 SHA1SumValue();
00045 };
00046
00047 class SHA1Summation
00048 {
00049
00050 unsigned char Buffer[64] __attribute__((aligned(8)));
00051 unsigned char State[5*4] __attribute__((aligned(8)));
00052 unsigned char Count[2*4] __attribute__((aligned(8)));
00053 bool Done;
00054
00055 public:
00056
00057 bool Add(const unsigned char *inbuf,unsigned long inlen);
00058 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
00059 bool AddFD(int Fd,unsigned long Size);
00060 inline bool Add(const unsigned char *Beg,const unsigned char *End)
00061 {return Add(Beg,End-Beg);};
00062 SHA1SumValue Result();
00063
00064 SHA1Summation();
00065 };
00066
00067 #endif