]>
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 #ifdef APT_PKG_EXPOSE_STRING_VIEW
83 APT_HIDDEN
bool Set(APT::StringView Str
)
85 return Hex2Num(Str
,Sum
,sizeof(Sum
));
88 bool Set(std::string Str
)
90 return Hex2Num(Str
,Sum
,sizeof(Sum
));
93 inline void Set(unsigned char S
[N
/8])
95 for (int I
= 0; I
!= sizeof(Sum
); ++I
)
99 explicit HashSumValue(std::string
const &Str
)
101 memset(Sum
,0,sizeof(Sum
));
104 #ifdef APT_PKG_EXPOSE_STRING_VIEW
105 APT_HIDDEN
explicit HashSumValue(APT::StringView
const &Str
)
107 memset(Sum
,0,sizeof(Sum
));
110 APT_HIDDEN
explicit HashSumValue(const char *Str
)
112 memset(Sum
,0,sizeof(Sum
));
118 memset(Sum
,0,sizeof(Sum
));
122 class SummationImplementation
125 virtual bool Add(const unsigned char *inbuf
, unsigned long long inlen
) APT_NONNULL(2) = 0;
126 inline bool Add(const char *inbuf
, unsigned long long const inlen
) APT_NONNULL(2)
127 { return Add((const unsigned char *)inbuf
, inlen
); }
129 inline bool Add(const unsigned char *Data
) APT_NONNULL(2)
130 { return Add(Data
, strlen((const char *)Data
)); }
131 inline bool Add(const char *Data
) APT_NONNULL(2)
132 { return Add((const unsigned char *)Data
, strlen(Data
)); }
134 inline bool Add(const unsigned char *Beg
, const unsigned char *End
) APT_NONNULL(2,3)
135 { return Add(Beg
, End
- Beg
); }
136 inline bool Add(const char *Beg
, const char *End
) APT_NONNULL(2,3)
137 { return Add((const unsigned char *)Beg
, End
- Beg
); }
139 bool AddFD(int Fd
, unsigned long long Size
= 0);
140 bool AddFD(FileFd
&Fd
, unsigned long long Size
= 0);