#include <QFile>
#include <QImage>
#include <QPixmap>
+#include <QCryptographicHash>
// KDE
#include <KApplication>
-#include <KCodecs>
#include <KDebug>
#include <kde_file.h>
#include <KFileItem>
static QString generateThumbnailPath(const QString& uri, ThumbnailGroup::Enum group)
{
- KMD5 md5(QFile::encodeName(uri));
+ QByteArray md5 = QCryptographicHash::hash(QFile::encodeName(uri), QCryptographicHash::Md5);
QString baseDir = ThumbnailProvider::thumbnailBaseDir(group);
- return baseDir + QString(QFile::encodeName(md5.hexDigest())) + ".png";
+ return baseDir + QString(QFile::encodeName(md5.toHex())) + ".png";
}
//------------------------------------------------------------------------
macro_optional_find_package(Sqlite)
macro_log_feature(SQLITE_FOUND "SQLite" "SQLite is a Binary-Database" "" FALSE "" "Needed for the SQLite-Backend of the KGet-History and the Kopete-Statistic-Plugin")
-macro_optional_find_package(QCA2)
-macro_log_feature(QCA2_FOUND "QCA2" "Qt Cryptographic Architecture" "http://delta.affinix.com/qca" FALSE "2.0.0" "Needed for the KGet bittorrent-plugin and some Kopete plugins")
-
macro_optional_find_package(QGpgme)
macro_log_feature(QGPGME_FOUND "QGpgME" "The QGpgME library" "http://www.kde.org" FALSE "" "QGpgME is required to have signature verifying support in KGet.")
add_definitions(-DDEBUG)
endif(CMAKE_BUILD_TYPE MATCHES debugfull)
-if(QCA2_FOUND)
- add_definitions(-DHAVE_QCA2)
- include_directories(${QCA2_INCLUDE_DIR})
-endif(QCA2_FOUND)
-
if(QGPGME_FOUND)
add_definitions(-DHAVE_QGPGME)
include_directories(${QGPGME_INCLUDE_DIR})
target_link_libraries(kgetcore ${QT_QTSQL_LIBRARY})
endif (SQLITE_FOUND)
-if (QCA2_FOUND)
- target_link_libraries(kgetcore ${QCA2_LIBRARIES})
-endif (QCA2_FOUND)
-
if (QGPGME_FOUND)
target_link_libraries(kgetcore ${QGPGME_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
add_executable(kget ${kget_SRCS})
target_link_libraries(kget ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${KDE4_KCMUTILS_LIBRARY} kgetcore ${KDE4_KNOTIFYCONFIG_LIBS})
-if(QCA2_FOUND)
- target_link_libraries(kget ${QCA2_LIBRARIES})
-endif(QCA2_FOUND)
if (QGPGME_FOUND)
target_link_libraries(kget ${QGPGME_LIBRARIES})
continue;
}
- const QString hash = Verifier::checksum(url, type, &m_abort);
+ const QString hash = Verifier::checksum(url, type);
kDebug(5001) << "Type:" << type << "Calculated checksum:" << hash << "Entered checksum:" << checksum;
const bool fileVerified = (hash == checksum);
- if (m_abort)
- {
- return;
- }
-
m_mutex.lock();
- if (!m_abort)
- {
- emit verified(type, fileVerified, url);
- emit verified(fileVerified);
- }
+ emit verified(type, fileVerified, url);
+ emit verified(fileVerified);
run = m_files.count();
m_mutex.unlock();
}
return;
}
- const QStringList fileChecksums = Verifier::partialChecksums(url, type, length, &m_abort).checksums();
- if (m_abort)
- {
- emit brokenPieces(broken, length);
- return;
- }
-
+ const QStringList fileChecksums = Verifier::partialChecksums(url, type, length).checksums();
if (fileChecksums.size() != checksums.size())
{
kDebug(5001) << "Number of checksums differs!";
#include <QtCore/QFile>
#include <QtCore/QScopedPointer>
+#include <QtCore/QCryptographicHash>
#include <QtXml/qdom.h>
-#include <KCodecs>
#include <KDebug>
-#ifdef HAVE_QCA2
-#include <QtCrypto>
-#endif
-
//TODO use mutable to make some methods const?
-const QStringList VerifierPrivate::SUPPORTED = (QStringList() << "sha512" << "sha384" << "sha256" << "ripmed160" << "sha1" << "md5" << "md4");
+// TODO: implement md4 support
+const QStringList VerifierPrivate::SUPPORTED = (QStringList() << "sha1" << "md5" << "md4");
const QString VerifierPrivate::MD5 = QString("md5");
-const int VerifierPrivate::DIGGESTLENGTH[] = {128, 96, 64, 40, 40, 32, 32};
const int VerifierPrivate::MD5LENGTH = 32;
+const QString VerifierPrivate::SHA1 = QString("sha1");
+const int VerifierPrivate::SHA1LENGTH = 40;
+const int VerifierPrivate::DIGGESTLENGTH[] = {40, 32, 32};
const int VerifierPrivate::PARTSIZE = 500 * 1024;
VerifierPrivate::~VerifierPrivate()
qDeleteAll(partialSums.begin(), partialSums.end());
}
-QString VerifierPrivate::calculatePartialChecksum(QFile *file, const QString &type, KIO::fileoffset_t startOffset, int pieceLength, KIO::filesize_t fileSize, bool *abortPtr)
+QString VerifierPrivate::calculatePartialChecksum(QFile *file, const QString &type, KIO::fileoffset_t startOffset, int pieceLength, KIO::filesize_t fileSize)
{
if (!file)
{
pieceLength = fileSize - startOffset;
}
-#ifdef HAVE_QCA2
- QCA::Hash hash(type);
-
- //it can be that QCA2 does not support md5, e.g. when Qt is compiled locally
- KMD5 md5Hash;
- const bool useMd5 = (type == MD5);
-#else //NO QCA2
- if (type != MD5)
- {
+ if (type != MD5 && type != SHA1) {
return QString();
}
- KMD5 hash;
-#endif //HAVE_QCA2
//we only read 512kb each time, to save RAM
int numData = pieceLength / PARTSIZE;
if (!numData && !dataRest)
{
- QString();
+ return QString();
}
+ QCryptographicHash *hash = 0;
+ if (type == MD5) {
+ hash = new QCryptographicHash(QCryptographicHash::Md5);
+ } else if (type == SHA1) {
+ hash = new QCryptographicHash(QCryptographicHash::Sha1);
+ }
int k = 0;
for (k = 0; k < numData; ++k)
{
return QString();
}
- if (abortPtr && *abortPtr)
- {
- return QString();
- }
-
QByteArray data = file->read(PARTSIZE);
-#ifdef HAVE_QCA2
- if (useMd5) {
- md5Hash.update(data);
- } else {
- hash.update(data);
- }
-#else //NO QCA2
- hash.update(data);
-#endif //HAVE_QCA2
+ hash->addData(data);
}
//now read the rest
}
QByteArray data = file->read(dataRest);
-#ifdef HAVE_QCA2
- if (useMd5) {
- md5Hash.update(data);
- } else {
- hash.update(data);
- }
-#else //NO QCA2
- hash.update(data);
-#endif //HAVE_QCA2
+ hash->addData(data);
}
-#ifdef HAVE_QCA2
- return (useMd5 ? QString(md5Hash.hexDigest()) : QString(QCA::arrayToHex(hash.final().toByteArray())));
-#else //NO QCA2
- return QString(hash.hexDigest());
-#endif //HAVE_QCA2
+ return QString(hash->result().toHex());
}
QStringList VerifierPrivate::orderChecksumTypes(Verifier::ChecksumStrength strength) const
QStringList Verifier::supportedVerficationTypes()
{
QStringList supported;
-#ifdef HAVE_QCA2
- QStringList supportedTypes = QCA::Hash::supportedTypes();
- for (int i = 0; i < VerifierPrivate::SUPPORTED.count(); ++i)
- {
- if (supportedTypes.contains(VerifierPrivate::SUPPORTED.at(i)))
- {
- supported << VerifierPrivate::SUPPORTED.at(i);
- }
- }
-#endif //HAVE_QCA2
-
if (!supported.contains(VerifierPrivate::MD5))
{
- supported << VerifierPrivate::MD5;
+ supported << VerifierPrivate::MD5 << VerifierPrivate::SHA1;
}
return supported;
int Verifier::diggestLength(const QString &type)
{
- if (type == VerifierPrivate::MD5)
- {
+ if (type == VerifierPrivate::MD5) {
return VerifierPrivate::MD5LENGTH;
+ } else if (type == VerifierPrivate::SHA1) {
+ return VerifierPrivate::SHA1LENGTH;
}
-#ifdef HAVE_QCA2
- if (QCA::isSupported(type.toLatin1()))
- {
- return VerifierPrivate::DIGGESTLENGTH[VerifierPrivate::SUPPORTED.indexOf(type)];
- }
-#endif //HAVE_QCA2
-
return 0;
}
d->thread.findBrokenPieces(pair.first, checksums, length, d->dest);
}
-QString Verifier::checksum(const KUrl &dest, const QString &type, bool *abortPtr)
+QString Verifier::checksum(const KUrl &dest, const QString &type)
{
QStringList supported = supportedVerficationTypes();
if (!supported.contains(type))
}
if (type == VerifierPrivate::MD5) {
- KMD5 hash;
- hash.update(file);
- QString final = QString(hash.hexDigest());
+ QByteArray hash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5);
file.close();
- return final;
- }
-
-
-#ifdef HAVE_QCA2
- QCA::Hash hash(type);
-
- //BEGIN taken from qca_basic.h and slightly adopted to allow abort
- char buffer[1024];
- int len;
-
- while ((len=file.read(reinterpret_cast<char*>(buffer), sizeof(buffer))) > 0)
- {
- hash.update(buffer, len);
- if (abortPtr && *abortPtr)
- {
- hash.final();
- file.close();
- return QString();
- }
+ return hash.toHex();
+ } else if (type == VerifierPrivate::SHA1) {
+ QByteArray hash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Sha1);
+ file.close();
+ return hash.toHex();
}
- //END
-
- QString final = QString(QCA::arrayToHex(hash.final().toByteArray()));
- file.close();
- return final;
-#endif //HAVE_QCA2
return QString();
}
-PartialChecksums Verifier::partialChecksums(const KUrl &dest, const QString &type, KIO::filesize_t length, bool *abortPtr)
+PartialChecksums Verifier::partialChecksums(const KUrl &dest, const QString &type, KIO::filesize_t length)
{
QStringList checksums;
//create all the checksums for the pieces
for (int i = 0; i < numPieces; ++i)
{
- QString hash = VerifierPrivate::calculatePartialChecksum(&file, type, length * i, length, fileSize, abortPtr);
+ QString hash = VerifierPrivate::calculatePartialChecksum(&file, type, length * i, length, fileSize);
if (hash.isEmpty())
{
file.close();
/**
* Creates the checksum type of the file dest
- * @param abortPtr makes it possible to abort the calculation of the checksum from another thread
*/
- static QString checksum(const KUrl &dest, const QString &type, bool *abortPtr);
+ static QString checksum(const KUrl &dest, const QString &type);
/**
* Create partial checksums of type for file dest
- * @param abortPtr makes it possible to abort the calculation of the checksums from another thread
* @note the length of the partial checksum (if not defined = 0) is not less than 512 kb
* and there won't be more partial checksums than 101
*/
- static PartialChecksums partialChecksums(const KUrl &dest, const QString &type, KIO::filesize_t length = 0, bool *abortPtr = 0);
+ static PartialChecksums partialChecksums(const KUrl &dest, const QString &type, KIO::filesize_t length = 0);
/**
* @note only call verify() when this function returns true
~VerifierPrivate();
- static QString calculatePartialChecksum(QFile *file, const QString &type, KIO::fileoffset_t startOffset, int pieceLength, KIO::filesize_t fileSize = 0, bool *abortPtr = 0);
+ static QString calculatePartialChecksum(QFile *file, const QString &type, KIO::fileoffset_t startOffset, int pieceLength, KIO::filesize_t fileSize = 0);
QStringList orderChecksumTypes(Verifier::ChecksumStrength strength) const;
static const QStringList SUPPORTED;
static const QString MD5;
- static const int DIGGESTLENGTH[];
static const int MD5LENGTH;
+ static const QString SHA1;
+ static const int SHA1LENGTH;
+ static const int DIGGESTLENGTH[];
static const int PARTSIZE;
};
#include "core/transfer.h"
#include "core/transfergroup.h"
-#ifdef HAVE_QCA2
-#include <QtCrypto>
-#endif
-
class ViewsContainer;
class DropTarget;
class DBusKgetWrapper;
bool m_doTesting; // UnitTest flag
HttpServer *m_webinterface;
-
-#ifdef HAVE_QCA2
- QCA::Initializer m_qcaInit;
-#endif //HAVE_QCA2
};
#endif
#===========Verifier===========
-if (QCA2_FOUND)
- kde4_add_test(kget-verifiertest verifiertest.cpp)
+kde4_add_test(kget-verifiertest verifiertest.cpp)
- target_link_libraries(kget-verifiertest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QCA2_LIBRARIES} kgetcore)
-endif (QCA2_FOUND)
+target_link_libraries(kget-verifiertest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QCA2_LIBRARIES} kgetcore)
#===========Scheduler===========
return;
}
- QCOMPARE(Verifier::checksum(m_file, type, 0), checksum);
+ QCOMPARE(Verifier::checksum(m_file, type), checksum);
}
void VerfierTest::testChecksum_data()
QFETCH(QStringList, checksums);
QFETCH(bool, result);
- const PartialChecksums partial = Verifier::partialChecksums(m_file, type, length, 0);
+ const PartialChecksums partial = Verifier::partialChecksums(m_file, type, length);
QCOMPARE((partial.checksums() == checksums), result);
}
#include <QStringList>
#include <KUrl>
-#ifdef HAVE_QCA2
-#include <QtCrypto>
-#endif
-
class KTempDir;
class VerfierTest : public QObject
bool expectedResult(bool expected, const QString &type);
private:
-#ifdef HAVE_QCA2
- QCA::Initializer m_qcaInit;
-#endif //HAVE_QCA2
QScopedPointer<KTempDir> m_tempDir;
KUrl m_file;
const QStringList m_supported;
return;
}
- const QString hash = Verifier::checksum(url, type, &abort);
+ const QString hash = Verifier::checksum(url, type);
if (!hash.isEmpty()) {
file.verification.hashes[type] = hash;
}
return;
}
- const PartialChecksums partialChecksums = Verifier::partialChecksums(url, type, 0, &abort);
+ const PartialChecksums partialChecksums = Verifier::partialChecksums(url, type, 0);
if (partialChecksums.isValid()) {
KGetMetalink::Pieces pieces;
pieces.type = type;
#include <QClipboard>
#include <QLabel>
#include <QFile>
+#include <QCryptographicHash>
#include <KApplication>
#include <KMessageBox>
#include <KLineEdit>
#include <KLocale>
-#include <KCodecs>
#include <KLed>
setButtonText(Apply, i18n("Compare MD5 with Clipboard"));
QFile f(url.path());
- KMD5 checkfile;
+ QCryptographicHash checkfile(QCryptographicHash::Md5);
if (f.open(QIODevice::ReadOnly)) {
- checkfile.update(f);
- f.close();
+ checkfile.addData(f.readAll());
+ f.close();
}
- m_md5sum = QLatin1String( checkfile.hexDigest().constData() );
+ m_md5sum = QLatin1String( checkfile.result().toHex() );
QWidget *page = new QWidget(this);
#include "personimpl.h"
#include <kcharsets.h>
-#include <kcodecs.h>
#include <kdatetime.h>
#include <QtCore/QByteArray>
#include <QtCore/QDateTime>
#include <QtCore/QRegExp>
#include <QtCore/QString>
+#include <QtCore/QCryptographicHash>
#include <kdebug.h>
namespace Syndication {
-KMD5 md5Machine;
-
unsigned int calcHash(const QString& str)
{
return calcHash(str.toUtf8());
QString calcMD5Sum(const QString& str)
{
- md5Machine.reset();
- md5Machine.update(str.toUtf8());
- return QLatin1String(md5Machine.hexDigest().constData());
+ return QLatin1String(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5).toHex());
}
QString resolveEntities(const QString& str)