/* */ #ifndef D_MESSAGE_DIGEST_HELPER_H #define D_MESSAGE_DIGEST_HELPER_H #include "common.h" #include #include "SharedHandle.h" namespace aria2 { class BinaryStream; class MessageDigest; class MessageDigestHelper { private: static SharedHandle sha1Ctx_; MessageDigestHelper(); public: /** * staticSHA1DigestInit(), staticSHA1DigestFree(), staticSHA1Digest() * use statically declared MessageDigest sha1Ctx_. */ /** * Initializes sha1Ctx_ */ static void staticSHA1DigestInit(); /** * Frees allocated resources for sha1Ctx_ */ static void staticSHA1DigestFree(); static std::string staticSHA1DigestHexDigest (const SharedHandle& bs, off_t offset, uint64_t length); /** * ctx must be initialized or reseted before calling this function. * Returns hex digest string, not *raw* digest */ static std::string hexDigest (const SharedHandle& ctx, const SharedHandle& bs, off_t offset, uint64_t length); /** * 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 SharedHandle& ctx, const void* data, size_t length); }; } // namespace aria2 #endif // D_MESSAGE_DIGEST_HELPER_H