From ce5cb5bc57ae95ca920b0a8b4715a201a491d897 Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 12 May 2010 16:52:19 +0200 Subject: Got rid of crypto++ dependency Replaced calls to crypto++ with QCryptographicHash --- helper.cpp | 45 ++++++++++++++++++++++----------------------- shemov.pro | 2 -- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/helper.cpp b/helper.cpp index e30b299..1b8640b 100644 --- a/helper.cpp +++ b/helper.cpp @@ -10,12 +10,7 @@ #include #include #include - -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include -#include -#include -#include +#include #include "helper.h" @@ -41,8 +36,8 @@ namespace Helper { retval = "video/"; } } - return retval; } + return retval; } const QString md5Sum(const QString &path){ @@ -51,28 +46,32 @@ namespace Helper { return QString(); } - using namespace CryptoPP; - Weak::MD5 hash; - std::string res; QString retval; + QCryptographicHash h(QCryptographicHash::Md5); + QFile file(path); + file.open(QIODevice::ReadOnly); + qint64 read = 0; if(info.size() < (5 * 1024 * 1024)){ - FileSource f(qPrintable(path), true, new HashFilter(hash, new HexEncoder(new StringSink(res)))); - retval = QString::fromStdString(res).toLower(); + QByteArray data(4096, '\0'); + do { + read = file.read(data.data(), 4096); + h.addData(data.data(), read); + } while (read == 4096); + QByteArray res = h.result(); + retval = res.toHex().toLower(); }else{ - QFile file(path); - file.open(QIODevice::ReadOnly); + QByteArray data(512, '\0'); int offset = info.size() / 3; file.seek(offset); int numBytes = 512 * 1024; - char *data = new char[numBytes]; - int read = file.read(data, numBytes); - if(read != numBytes){ - delete [] data; - return QString(); - } - StringSource s((byte*)data, numBytes, true, new HashFilter(hash, new HexEncoder(new StringSink(res)))); - retval = QString::fromStdString(res).toLower(); - delete [] data; + int readBytes = 0; + do { + read = file.read(data.data(), 512); + readBytes += read; + h.addData(data.data(), read); + } while(readBytes < numBytes); + QByteArray res = h.result(); + retval = res.toHex().toLower(); } return retval; } diff --git a/shemov.pro b/shemov.pro index c4f7449..1201dbd 100644 --- a/shemov.pro +++ b/shemov.pro @@ -78,6 +78,4 @@ HEADERS = listitem.h \ graphbarwidget.h \ programconfigurator.h LIBS += -lmagic -LIBS += -lcryptopp -INCLUDEPATH += /usr/include/cryptopp RESOURCES = shemov.qrc -- cgit v1.2.3-70-g09d2