diff --git a/CMakeLists.txt b/CMakeLists.txt index 0af5b9314..a59a9d0f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ set(sources string_util file gzip + hasher http_connection http_stream http_parser diff --git a/Jamfile b/Jamfile index 418a0aa1b..e0d2834bb 100755 --- a/Jamfile +++ b/Jamfile @@ -487,6 +487,7 @@ SOURCES = string_util file gzip + hasher http_connection http_stream http_parser diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 745cdb089..e48450baf 100644 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -71,90 +71,22 @@ namespace libtorrent { public: - hasher() - { -#ifdef TORRENT_USE_GCRYPT - gcry_md_open(&m_context, GCRY_MD_SHA1, 0); -#elif defined TORRENT_USE_OPENSSL - SHA1_Init(&m_context); -#else - SHA1_init(&m_context); -#endif - } - hasher(const char* data, int len) - { - TORRENT_ASSERT(data != 0); - TORRENT_ASSERT(len > 0); -#ifdef TORRENT_USE_GCRYPT - gcry_md_open(&m_context, GCRY_MD_SHA1, 0); - gcry_md_write(m_context, data, len); -#elif defined TORRENT_USE_OPENSSL - SHA1_Init(&m_context); - SHA1_Update(&m_context, reinterpret_cast(data), len); -#else - SHA1_init(&m_context); - SHA1_update(&m_context, reinterpret_cast(data), len); -#endif - } + hasher(); + hasher(const char* data, int len); #ifdef TORRENT_USE_GCRYPT - hasher(hasher const& h) - { - gcry_md_copy(&m_context, h.m_context); - } - - hasher& operator=(hasher const& h) - { - gcry_md_close(m_context); - gcry_md_copy(&m_context, h.m_context); - return *this; - } + hasher(hasher const& h); + hasher& operator=(hasher const& h); #endif void update(std::string const& data) { update(data.c_str(), data.size()); } - void update(const char* data, int len) - { - TORRENT_ASSERT(data != 0); - TORRENT_ASSERT(len > 0); -#ifdef TORRENT_USE_GCRYPT - gcry_md_write(m_context, data, len); -#elif defined TORRENT_USE_OPENSSL - SHA1_Update(&m_context, reinterpret_cast(data), len); -#else - SHA1_update(&m_context, reinterpret_cast(data), len); -#endif - } + void update(const char* data, int len); + sha1_hash final(); - sha1_hash final() - { - sha1_hash digest; -#ifdef TORRENT_USE_GCRYPT - gcry_md_final(m_context); - digest.assign((const char*)gcry_md_read(m_context, 0)); -#elif defined TORRENT_USE_OPENSSL - SHA1_Final(digest.begin(), &m_context); -#else - SHA1_final(digest.begin(), &m_context); -#endif - return digest; - } - - void reset() - { -#ifdef TORRENT_USE_GCRYPT - gcry_md_reset(m_context); -#elif defined TORRENT_USE_OPENSSL - SHA1_Init(&m_context); -#else - SHA1_init(&m_context); -#endif - } + void reset(); #ifdef TORRENT_USE_GCRYPT - ~hasher() - { - gcry_md_close(m_context); - } + ~hasher(); #endif private: diff --git a/src/Makefile.am b/src/Makefile.am index 1a1716caa..cbd2a606f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ libtorrent_rasterbar_la_SOURCES = \ file_pool.cpp \ file_storage.cpp \ gzip.cpp \ + hasher.cpp \ http_connection.cpp \ http_parser.cpp \ http_seed_connection.cpp \