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