|
|
@ -28,6 +28,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "infohash.h" |
|
|
|
#include "infohash.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QByteArray> |
|
|
|
#include <QHash> |
|
|
|
#include <QHash> |
|
|
|
|
|
|
|
|
|
|
|
using namespace BitTorrent; |
|
|
|
using namespace BitTorrent; |
|
|
@ -41,29 +42,25 @@ InfoHash::InfoHash(const libtorrent::sha1_hash &nativeHash) |
|
|
|
: m_valid(true) |
|
|
|
: m_valid(true) |
|
|
|
, m_nativeHash(nativeHash) |
|
|
|
, m_nativeHash(nativeHash) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char out[(libtorrent::sha1_hash::size * 2) + 1]; |
|
|
|
const QByteArray raw = QByteArray::fromRawData(nativeHash.data(), libtorrent::sha1_hash::size); |
|
|
|
libtorrent::to_hex(reinterpret_cast<const char*>(&m_nativeHash[0]), libtorrent::sha1_hash::size, out); |
|
|
|
m_hashString = QString::fromLatin1(raw.toHex()); |
|
|
|
m_hashString = QString(out); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
InfoHash::InfoHash(const QString &hashString) |
|
|
|
InfoHash::InfoHash(const QString &hashString) |
|
|
|
: m_valid(false) |
|
|
|
: m_valid(false) |
|
|
|
, m_hashString(hashString) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
QByteArray raw = m_hashString.toLatin1(); |
|
|
|
if (hashString.size() != (libtorrent::sha1_hash::size * 2)) |
|
|
|
if (raw.size() == 40) |
|
|
|
return; |
|
|
|
m_valid = libtorrent::from_hex(raw.constData(), 40, reinterpret_cast<char*>(&m_nativeHash[0])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QByteArray raw = QByteArray::fromHex(hashString.toLatin1()); |
|
|
|
|
|
|
|
if (raw.size() != libtorrent::sha1_hash::size) // QByteArray::fromHex() will skip over invalid characters
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
InfoHash::InfoHash(const InfoHash &other) |
|
|
|
m_valid = true; |
|
|
|
: m_valid(other.m_valid) |
|
|
|
m_hashString = hashString; |
|
|
|
, m_nativeHash(other.m_nativeHash) |
|
|
|
m_nativeHash.assign(raw.constData()); |
|
|
|
, m_hashString(other.m_hashString) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InfoHash::isValid() const |
|
|
|
bool InfoHash::isValid() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return m_valid; |
|
|
|
return m_valid; |
|
|
@ -74,25 +71,23 @@ InfoHash::operator libtorrent::sha1_hash() const |
|
|
|
return m_nativeHash; |
|
|
|
return m_nativeHash; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InfoHash::operator QString() const |
|
|
|
InfoHash::operator QString() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return m_hashString; |
|
|
|
return m_hashString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BitTorrent::operator==(const InfoHash &left, const InfoHash &right) |
|
|
|
bool InfoHash::operator==(const InfoHash &other) const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return (m_nativeHash == other.m_nativeHash); |
|
|
|
return (static_cast<libtorrent::sha1_hash>(left) |
|
|
|
|
|
|
|
== static_cast<libtorrent::sha1_hash>(right)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right) |
|
|
|
bool InfoHash::operator!=(const InfoHash &other) const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return (m_nativeHash != other.m_nativeHash); |
|
|
|
return !(left == right); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint BitTorrent::qHash(const InfoHash &key, uint seed) |
|
|
|
uint BitTorrent::qHash(const InfoHash &key, const uint seed) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return qHash(static_cast<QString>(key), seed); |
|
|
|
return ::qHash(static_cast<QString>(key), seed); |
|
|
|
} |
|
|
|
} |
|
|
|