From 840ae26b2dce30eab0139c5a2fd1522b4fd7603f Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 27 May 2011 12:26:59 +0200 Subject: [PATCH] use QCryptographicHash instead of QCA --- package.cpp | 38 +++++++++++--------------------------- private/package_p.h | 5 ++--- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/package.cpp b/package.cpp index ff1b29fcc..151828a5c 100644 --- a/package.cpp +++ b/package.cpp @@ -26,10 +26,6 @@ #include #include -#ifdef QCA2_FOUND -#include -#endif - #include #include #include @@ -319,8 +315,7 @@ const PackageStructure::Ptr Package::structure() const return d->structure; } -#ifdef QCA2_FOUND -void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCA::Hash &hash) +void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash) { // hash is calculated as a function of: // * files ordered alphabetically by name, with each file's: @@ -336,19 +331,19 @@ void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, const QDir::Filters filters = QDir::Hidden | QDir::System | QDir::NoDotAndDotDot; foreach (const QString &file, dir.entryList(QDir::Files | filters, sorting)) { if (!subPath.isEmpty()) { - hash.update(subPath.toUtf8()); + hash.addData(subPath.toUtf8()); } - hash.update(file.toUtf8()); + hash.addData(file.toUtf8()); QFileInfo info(dir.path() + '/' + file); if (info.isSymLink()) { - hash.update(info.symLinkTarget().toUtf8()); + hash.addData(info.symLinkTarget().toUtf8()); } else { QFile f(info.filePath()); if (f.open(QIODevice::ReadOnly)) { while (!f.atEnd()) { - hash.update(f.read(1024)); + hash.addData(f.read(1024)); } } else { kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading. " @@ -359,40 +354,33 @@ void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, foreach (const QString &subDirPath, dir.entryList(QDir::Dirs | filters, sorting)) { const QString relativePath = subPath + subDirPath + '/'; - hash.update(relativePath.toUtf8()); + hash.addData(relativePath.toUtf8()); QDir subDir(dir.path()); subDir.cd(subDirPath); if (subDir.path() != subDir.canonicalPath()) { - hash.update(subDir.canonicalPath().toUtf8()); + hash.addData(subDir.canonicalPath().toUtf8()); } else { updateHash(basePath, relativePath, subDir, hash); } } } -#endif QString Package::contentsHash() const { -#ifdef QCA2_FOUND if (!d->valid) { kWarning() << "can not create hash due to Package being invalid"; return QString(); } - if (!QCA::isSupported("sha1")) { - kWarning() << "can not create hash for" << path() << "due to no SHA1 support in QCA2"; - return QString(); - } - - QCA::Hash hash("sha1"); + QCryptographicHash hash(QCryptographicHash::Sha1); QString metadataPath = d->structure->path() + "metadata.desktop"; if (QFile::exists(metadataPath)) { QFile f(metadataPath); if (f.open(QIODevice::ReadOnly)) { while (!f.atEnd()) { - hash.update(f.read(1024)); + hash.addData(f.read(1024)); } } else { kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading."; @@ -416,12 +404,8 @@ QString Package::contentsHash() const d->updateHash(basePath, QString(), dir, hash); } - return QCA::arrayToHex(hash.final().toByteArray()); -#else - // no QCA2! - kWarning() << "can not create hash for" << path() << "due to no cryptographic support (QCA2)"; - return QString(); -#endif + + return hash.result(); } //TODO: provide a version of this that allows one to ask for certain types of packages, etc? diff --git a/private/package_p.h b/private/package_p.h index 92203b071..5b9ce22d7 100644 --- a/private/package_p.h +++ b/private/package_p.h @@ -23,6 +23,7 @@ #include "../package.h" #include "../service.h" +#include #include namespace Plasma @@ -41,9 +42,7 @@ public: void unpublish(); bool isPublished() const; -#ifdef QCA2_FOUND - void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCA::Hash &hash); -#endif + void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash); PackageStructure::Ptr structure; Service *service;