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