/* */ #ifndef _D_MESSAGE_DIGEST_HELPER_H_ #define _D_MESSAGE_DIGEST_HELPER_H_ #include "common.h" #include "SharedHandle.h" #include "messageDigest.h" #include namespace aria2 { class BinaryStream; class MessageDigestHelper { private: static MessageDigestContext* sha1Ctx_; public: /** * Returns message digest in hexadecimal representation. * Digest algorithm is specified by algo. */ static std::string digest(const std::string& algo, const SharedHandle& bs, off_t offset, uint64_t length); static std::string digest(const std::string& algo, const void* data, size_t length); static std::string digestString(const std::string& algo, const std::string& data) { return digest(algo, data.c_str(), data.size()); } /** * staticSHA1DigestInit(), staticSHA1DigestFree(), staticSHA1Digest() * use statically declared MessageDigestContext sha1Ctx_. */ /** * Initializes sha1Ctx_ */ static void staticSHA1DigestInit(); /** * Frees allocated resources for sha1Ctx_ */ static void staticSHA1DigestFree(); static std::string staticSHA1Digest(const SharedHandle& bs, off_t offset, uint64_t length); /** * ctx must be initialized or reseted before calling this function. */ static std::string digest(MessageDigestContext* ctx, const SharedHandle& bs, off_t offset, uint64_t length); /** * Calculates message digest of file denoted by filename. * Returns message digest in hexadecimal representation. * Digest algorithm is specified by algo. */ static std::string digest(const std::string& algo, const std::string& filename); /** * Stores *raw* message digest into md. * Throws exception when mdLength is less than the size of message digest. */ static void digest(unsigned char* md, size_t mdLength, const std::string& algo, const void* data, size_t length); }; } // namespace aria2 #endif // _D_MESSAGE_DIGEST_HELPER_H_