X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/8f3ba4e8708cb72be19dacc2af4f601ee5fea292..HEAD:/apt-pkg/contrib/hashsum_template.h?ds=sidebyside diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h index c109a8212..e5032d02f 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -10,23 +10,43 @@ #ifndef APTPKG_HASHSUM_TEMPLATE_H #define APTPKG_HASHSUM_TEMPLATE_H + #include #include +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include +#endif + +#include + +#ifndef APT_10_CLEANER_HEADERS +#include #include #include +#endif +#ifndef APT_8_CLEANER_HEADERS +using std::string; +using std::min; +#endif + +class FileFd; template class HashSumValue { unsigned char Sum[N/8]; - + public: // Accessors bool operator ==(const HashSumValue &rhs) const { return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0; - }; + } + bool operator !=(const HashSumValue &rhs) const + { + return memcmp(Sum,rhs.Sum,sizeof(Sum)) != 0; + } std::string Value() const { @@ -36,7 +56,7 @@ class HashSumValue }; char Result[((N/8)*2)+1]; Result[(N/8)*2] = 0; - + // Convert each char into two letters int J = 0; int I = 0; @@ -46,35 +66,53 @@ class HashSumValue Result[I + 1] = Conv[Sum[J] & 0xF]; } return std::string(Result); - }; - + } + inline void Value(unsigned char S[N/8]) { - for (int I = 0; I != sizeof(Sum); I++) + for (int I = 0; I != sizeof(Sum); ++I) S[I] = Sum[I]; - }; + } - inline operator std::string() const + inline operator std::string() const { return Value(); - }; + } - bool Set(std::string Str) +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN bool Set(APT::StringView Str) { return Hex2Num(Str,Sum,sizeof(Sum)); - }; - - inline void Set(unsigned char S[N/8]) + } +#else + bool Set(std::string Str) { - for (int I = 0; I != sizeof(Sum); I++) + return Hex2Num(Str,Sum,sizeof(Sum)); + } +#endif + inline void Set(unsigned char S[N/8]) + { + for (int I = 0; I != sizeof(Sum); ++I) Sum[I] = S[I]; - }; + } - HashSumValue(std::string Str) + explicit HashSumValue(std::string const &Str) { memset(Sum,0,sizeof(Sum)); Set(Str); } +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN explicit HashSumValue(APT::StringView const &Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } + APT_HIDDEN explicit HashSumValue(const char *Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } +#endif HashSumValue() { memset(Sum,0,sizeof(Sum)); @@ -84,21 +122,22 @@ class HashSumValue class SummationImplementation { public: - virtual bool Add(const unsigned char *inbuf, unsigned long long inlen) = 0; - inline bool Add(const char *inbuf, unsigned long long const inlen) - { return Add((unsigned char *)inbuf, inlen); }; + virtual bool Add(const unsigned char *inbuf, unsigned long long inlen) APT_NONNULL(2) = 0; + inline bool Add(const char *inbuf, unsigned long long const inlen) APT_NONNULL(2) + { return Add((const unsigned char *)inbuf, inlen); } - inline bool Add(const unsigned char *Data) - { return Add(Data, strlen((const char *)Data)); }; - inline bool Add(const char *Data) - { return Add((const unsigned char *)Data, strlen((const char *)Data)); }; + inline bool Add(const unsigned char *Data) APT_NONNULL(2) + { return Add(Data, strlen((const char *)Data)); } + inline bool Add(const char *Data) APT_NONNULL(2) + { return Add((const unsigned char *)Data, strlen(Data)); } - inline bool Add(const unsigned char *Beg, const unsigned char *End) - { return Add(Beg, End - Beg); }; - inline bool Add(const char *Beg, const char *End) - { return Add((const unsigned char *)Beg, End - Beg); }; + inline bool Add(const unsigned char *Beg, const unsigned char *End) APT_NONNULL(2,3) + { return Add(Beg, End - Beg); } + inline bool Add(const char *Beg, const char *End) APT_NONNULL(2,3) + { return Add((const unsigned char *)Beg, End - Beg); } bool AddFD(int Fd, unsigned long long Size = 0); + bool AddFD(FileFd &Fd, unsigned long long Size = 0); }; #endif