]>
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
21 unsigned char Sum
[N
/8];
26 bool operator ==(const HashSumValue
&rhs
) const
28 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) == 0;
30 bool operator !=(const HashSumValue
&rhs
) const
32 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) != 0;
35 std::string
Value() const
38 { '0','1','2','3','4','5','6','7','8','9','a','b',
41 char Result
[((N
/8)*2)+1];
44 // Convert each char into two letters
47 for (; I
!= (N
/8)*2; J
++,I
+= 2)
49 Result
[I
] = Conv
[Sum
[J
] >> 4];
50 Result
[I
+ 1] = Conv
[Sum
[J
] & 0xF];
52 return std::string(Result
);
55 inline void Value(unsigned char S
[N
/8])
57 for (int I
= 0; I
!= sizeof(Sum
); I
++)
61 inline operator std::string() const
66 bool Set(std::string Str
)
68 return Hex2Num(Str
,Sum
,sizeof(Sum
));
71 inline void Set(unsigned char S
[N
/8])
73 for (int I
= 0; I
!= sizeof(Sum
); I
++)
77 HashSumValue(std::string Str
)
79 memset(Sum
,0,sizeof(Sum
));
84 memset(Sum
,0,sizeof(Sum
));
88 class SummationImplementation
91 virtual bool Add(const unsigned char *inbuf
, unsigned long long inlen
) = 0;
92 inline bool Add(const char *inbuf
, unsigned long long const inlen
)
93 { return Add((unsigned char *)inbuf
, inlen
); };
95 inline bool Add(const unsigned char *Data
)
96 { return Add(Data
, strlen((const char *)Data
)); };
97 inline bool Add(const char *Data
)
98 { return Add((const unsigned char *)Data
, strlen((const char *)Data
)); };
100 inline bool Add(const unsigned char *Beg
, const unsigned char *End
)
101 { return Add(Beg
, End
- Beg
); };
102 inline bool Add(const char *Beg
, const char *End
)
103 { return Add((const unsigned char *)Beg
, End
- Beg
); };
105 bool AddFD(int Fd
, unsigned long long Size
= 0);