]>
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
13 #include <apt-pkg/fileutl.h>
20 #include <apt-pkg/strutl.h>
22 #ifndef APT_8_CLEANER_HEADERS
30 unsigned char Sum
[N
/8];
35 bool operator ==(const HashSumValue
&rhs
) const
37 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) == 0;
39 bool operator !=(const HashSumValue
&rhs
) const
41 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) != 0;
44 std::string
Value() const
47 { '0','1','2','3','4','5','6','7','8','9','a','b',
50 char Result
[((N
/8)*2)+1];
53 // Convert each char into two letters
56 for (; I
!= (N
/8)*2; J
++,I
+= 2)
58 Result
[I
] = Conv
[Sum
[J
] >> 4];
59 Result
[I
+ 1] = Conv
[Sum
[J
] & 0xF];
61 return std::string(Result
);
64 inline void Value(unsigned char S
[N
/8])
66 for (int I
= 0; I
!= sizeof(Sum
); I
++)
70 inline operator std::string() const
75 bool Set(std::string Str
)
77 return Hex2Num(Str
,Sum
,sizeof(Sum
));
80 inline void Set(unsigned char S
[N
/8])
82 for (int I
= 0; I
!= sizeof(Sum
); I
++)
86 HashSumValue(std::string Str
)
88 memset(Sum
,0,sizeof(Sum
));
93 memset(Sum
,0,sizeof(Sum
));
97 class SummationImplementation
100 virtual bool Add(const unsigned char *inbuf
, unsigned long long inlen
) = 0;
101 inline bool Add(const char *inbuf
, unsigned long long const inlen
)
102 { return Add((unsigned char *)inbuf
, inlen
); };
104 inline bool Add(const unsigned char *Data
)
105 { return Add(Data
, strlen((const char *)Data
)); };
106 inline bool Add(const char *Data
)
107 { return Add((const unsigned char *)Data
, strlen((const char *)Data
)); };
109 inline bool Add(const unsigned char *Beg
, const unsigned char *End
)
110 { return Add(Beg
, End
- Beg
); };
111 inline bool Add(const char *Beg
, const char *End
)
112 { return Add((const unsigned char *)Beg
, End
- Beg
); };
114 bool AddFD(int Fd
, unsigned long long Size
= 0);
115 bool AddFD(FileFd
&Fd
, unsigned long long Size
= 0);