]>
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
18 #ifndef APT_8_CLEANER_HEADERS
26 unsigned char Sum
[N
/8];
31 bool operator ==(const HashSumValue
&rhs
) const
33 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) == 0;
35 bool operator !=(const HashSumValue
&rhs
) const
37 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) != 0;
40 std::string
Value() const
43 { '0','1','2','3','4','5','6','7','8','9','a','b',
46 char Result
[((N
/8)*2)+1];
49 // Convert each char into two letters
52 for (; I
!= (N
/8)*2; J
++,I
+= 2)
54 Result
[I
] = Conv
[Sum
[J
] >> 4];
55 Result
[I
+ 1] = Conv
[Sum
[J
] & 0xF];
57 return std::string(Result
);
60 inline void Value(unsigned char S
[N
/8])
62 for (int I
= 0; I
!= sizeof(Sum
); I
++)
66 inline operator std::string() const
71 bool Set(std::string Str
)
73 return Hex2Num(Str
,Sum
,sizeof(Sum
));
76 inline void Set(unsigned char S
[N
/8])
78 for (int I
= 0; I
!= sizeof(Sum
); I
++)
82 HashSumValue(std::string Str
)
84 memset(Sum
,0,sizeof(Sum
));
89 memset(Sum
,0,sizeof(Sum
));
93 class SummationImplementation
96 virtual bool Add(const unsigned char *inbuf
, unsigned long long inlen
) = 0;
97 inline bool Add(const char *inbuf
, unsigned long long const inlen
)
98 { return Add((unsigned char *)inbuf
, inlen
); };
100 inline bool Add(const unsigned char *Data
)
101 { return Add(Data
, strlen((const char *)Data
)); };
102 inline bool Add(const char *Data
)
103 { return Add((const unsigned char *)Data
, strlen((const char *)Data
)); };
105 inline bool Add(const unsigned char *Beg
, const unsigned char *End
)
106 { return Add(Beg
, End
- Beg
); };
107 inline bool Add(const char *Beg
, const char *End
)
108 { return Add((const unsigned char *)Beg
, End
- Beg
); };
110 bool AddFD(int Fd
, unsigned long long Size
= 0);