]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum_template.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: hashsum_template.h,v 1.3 2001/05/07 05:05:47 jgg Exp $
4 /* ######################################################################
6 HashSumValueTemplate - Generic Storage for a hash value
8 ##################################################################### */
10 #ifndef APTPKG_HASHSUM_TEMPLATE_H
11 #define APTPKG_HASHSUM_TEMPLATE_H
24 unsigned char Sum
[N
/8];
29 bool operator ==(const HashSumValue
&rhs
) const
31 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) == 0;
33 bool operator !=(const HashSumValue
&rhs
) const
35 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) != 0;
41 { '0','1','2','3','4','5','6','7','8','9','a','b',
44 char Result
[((N
/8)*2)+1];
47 // Convert each char into two letters
50 for (; I
!= (N
/8)*2; J
++,I
+= 2)
52 Result
[I
] = Conv
[Sum
[J
] >> 4];
53 Result
[I
+ 1] = Conv
[Sum
[J
] & 0xF];
55 return string(Result
);
58 inline void Value(unsigned char S
[N
/8])
60 for (int I
= 0; I
!= sizeof(Sum
); I
++)
64 inline operator string() const
71 return Hex2Num(Str
,Sum
,sizeof(Sum
));
74 inline void Set(unsigned char S
[N
/8])
76 for (int I
= 0; I
!= sizeof(Sum
); I
++)
80 HashSumValue(string Str
)
82 memset(Sum
,0,sizeof(Sum
));
87 memset(Sum
,0,sizeof(Sum
));
91 class SummationImplementation
94 virtual bool Add(const unsigned char *inbuf
, unsigned long inlen
) = 0;
95 inline bool Add(const char *inbuf
, unsigned long const inlen
)
96 { return Add((unsigned char *)inbuf
, inlen
); };
98 inline bool Add(const unsigned char *Data
)
99 { return Add(Data
, strlen((const char *)Data
)); };
100 inline bool Add(const char *Data
)
101 { return Add((const unsigned char *)Data
, strlen((const char *)Data
)); };
103 inline bool Add(const unsigned char *Beg
, const unsigned char *End
)
104 { return Add(Beg
, End
- Beg
); };
105 inline bool Add(const char *Beg
, const char *End
)
106 { return Add((const unsigned char *)Beg
, End
- Beg
); };
108 bool AddFD(int Fd
, unsigned long Size
= 0);