X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/cf4ff3b78dc347188949370db914fe6329be6c99..baec76f5f0f9fcbd71f6e2afaa7fc85543bd624c:/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 97b6a4ad9..e5032d02f 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -10,20 +10,27 @@ #ifndef APTPKG_HASHSUM_TEMPLATE_H #define APTPKG_HASHSUM_TEMPLATE_H -#include #include #include -#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 { @@ -72,22 +79,40 @@ class HashSumValue return Value(); } +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN bool Set(APT::StringView Str) + { + return Hex2Num(Str,Sum,sizeof(Sum)); + } +#else bool Set(std::string Str) { 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)); @@ -97,18 +122,18 @@ 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) + 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) + inline bool Add(const unsigned char *Data) APT_NONNULL(2) { 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 char *Data) APT_NONNULL(2) + { return Add((const unsigned char *)Data, strlen(Data)); } - inline bool Add(const unsigned char *Beg, const unsigned char *End) + 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) + 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);