]>
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
16 #ifdef APT_PKG_EXPOSE_STRING_VIEW
17 #include <apt-pkg/string_view.h>
20 #include <apt-pkg/strutl.h>
22 #ifndef APT_10_CLEANER_HEADERS
23 #include <apt-pkg/fileutl.h>
27 #ifndef APT_8_CLEANER_HEADERS
37 unsigned char Sum
[N
/8];
42 bool operator ==(const HashSumValue
&rhs
) const
44 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) == 0;
46 bool operator !=(const HashSumValue
&rhs
) const
48 return memcmp(Sum
,rhs
.Sum
,sizeof(Sum
)) != 0;
51 std::string
Value() const
54 { '0','1','2','3','4','5','6','7','8','9','a','b',
57 char Result
[((N
/8)*2)+1];
60 // Convert each char into two letters
63 for (; I
!= (N
/8)*2; J
++,I
+= 2)
65 Result
[I
] = Conv
[Sum
[J
] >> 4];
66 Result
[I
+ 1] = Conv
[Sum
[J
] & 0xF];
68 return std::string(Result
);
71 inline void Value(unsigned char S
[N
/8])
73 for (int I
= 0; I
!= sizeof(Sum
); ++I
)
77 inline operator std::string() const
82 bool Set(std::string Str
)
84 return Hex2Num(Str
,Sum
,sizeof(Sum
));
86 #ifdef APT_PKG_EXPOSE_STRING_VIEW
87 APT_HIDDEN
bool Set(APT::StringView Str
)
89 return Hex2Num(Str
,Sum
,sizeof(Sum
));
91 APT_HIDDEN
bool Set(const char *Str
)
93 return Hex2Num(APT::StringView(Str
),Sum
,sizeof(Sum
));
96 inline void Set(unsigned char S
[N
/8])
98 for (int I
= 0; I
!= sizeof(Sum
); ++I
)
102 explicit HashSumValue(std::string
const &Str
)
104 memset(Sum
,0,sizeof(Sum
));
107 #ifdef APT_PKG_EXPOSE_STRING_VIEW
108 APT_HIDDEN
explicit HashSumValue(APT::StringView
const &Str
)
110 memset(Sum
,0,sizeof(Sum
));
113 APT_HIDDEN
explicit HashSumValue(const char *Str
)
115 memset(Sum
,0,sizeof(Sum
));
121 memset(Sum
,0,sizeof(Sum
));
125 class SummationImplementation
128 virtual bool Add(const unsigned char *inbuf
, unsigned long long inlen
) = 0;
129 inline bool Add(const char *inbuf
, unsigned long long const inlen
)
130 { return Add((const unsigned char *)inbuf
, inlen
); }
132 inline bool Add(const unsigned char *Data
)
133 { return Add(Data
, strlen((const char *)Data
)); }
134 inline bool Add(const char *Data
)
135 { return Add((const unsigned char *)Data
, strlen(Data
)); }
137 inline bool Add(const unsigned char *Beg
, const unsigned char *End
)
138 { return Add(Beg
, End
- Beg
); }
139 inline bool Add(const char *Beg
, const char *End
)
140 { return Add((const unsigned char *)Beg
, End
- Beg
); }
142 bool AddFD(int Fd
, unsigned long long Size
= 0);
143 bool AddFD(FileFd
&Fd
, unsigned long long Size
= 0);