move hasher implementation out of header file

This commit is contained in:
Arvid Norberg 2013-05-08 07:57:16 +00:00
parent 7745a2831d
commit 7f194b4542
4 changed files with 11 additions and 76 deletions

View File

@ -25,6 +25,7 @@ set(sources
string_util
file
gzip
hasher
http_connection
http_stream
http_parser

View File

@ -487,6 +487,7 @@ SOURCES =
string_util
file
gzip
hasher
http_connection
http_stream
http_parser

View File

@ -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<unsigned char const*>(data), len);
#else
SHA1_init(&m_context);
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(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<unsigned char const*>(data), len);
#else
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(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:

View File

@ -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 \