# HG changeset patch # User Andre Heinecke # Date 1392230713 0 # Node ID 2ad9a96518e39762bc5b87bb9d87fc794721557d # Parent c7da699f0310638de4217a9aee0a3cd584461214 Actually parse all elements in the list diff -r c7da699f0310 -r 2ad9a96518e3 tests/certlistparsertest.cpp --- a/tests/certlistparsertest.cpp Wed Feb 12 17:17:44 2014 +0000 +++ b/tests/certlistparsertest.cpp Wed Feb 12 18:45:13 2014 +0000 @@ -57,7 +57,7 @@ { const char *fname = "list-valid-signed.txt"; - QBENCHMARK { + QBENCHMARK_ONCE { CertificateList *certList = testWithFile(fname); delete certList; } diff -r c7da699f0310 -r 2ad9a96518e3 ui/certificatelist.cpp --- a/ui/certificatelist.cpp Wed Feb 12 17:17:44 2014 +0000 +++ b/ui/certificatelist.cpp Wed Feb 12 18:45:13 2014 +0000 @@ -2,6 +2,8 @@ #include +#define PARSER_VERSION "1" + CertificateList::CertificateList(const char *fileName) { char *data = NULL; @@ -9,7 +11,46 @@ mStatus = readAndVerifyList(fileName, &data, &size); - if (isValid()) { - mFileContent = QByteArray::fromRawData(data, size); + if (!isValid()) { + return; + } + + // Take the data into the Qt Universe where memory is plentiful + // and CPU's are fast :) + QStringList lines = QString::fromLatin1(data, size).split("\n"); + free(data); + data = NULL; + + for (int i = 0; i < lines.size(); ++i) { + QString curLine = lines[i].trimmed(); + if (curLine.startsWith("F:")) { + if (curLine.right(1) != PARSER_VERSION) { + qDebug() << "Invalid Format Version"; + mStatus = IncompatibleVersion; + return; + } + } else if (curLine.startsWith("D:")) { + bool ok = false; + qlonglong timestamp = 0; + + curLine.remove(0, 2); + timestamp = curLine.toLongLong(&ok); + if (!ok) { + qDebug() << "Invalid Date"; + mStatus = InvalidFormat; + return; + } + + mDate = QDateTime::fromMSecsSinceEpoch(timestamp * 1000); + } else if (curLine.startsWith("I:")) { + mCertificatesInstall << QByteArray::fromBase64(curLine.remove(0,2).toLatin1()); + } else if (curLine.startsWith("R:")) { + mCertificatesInstall << QByteArray::fromBase64(curLine.remove(0,2).toLatin1()); + } else if (curLine.startsWith("S:")) { + // Signature is verified in readAndVerifyList + continue; + } else if (!curLine.isEmpty()){ + qDebug () << "Don't know how to handle: " << curLine; + } } } diff -r c7da699f0310 -r 2ad9a96518e3 ui/certificatelist.h --- a/ui/certificatelist.h Wed Feb 12 17:17:44 2014 +0000 +++ b/ui/certificatelist.h Wed Feb 12 18:45:13 2014 +0000 @@ -18,7 +18,7 @@ class QByteArray; #include -#include +#include #include #include "listutil.h" @@ -35,8 +35,9 @@ private: QString mFileName; - QByteArray mFileContent; + QList mCertificatesInstall; + QList mCertificatesRemove; list_status_t mStatus; - QDate mDate; + QDateTime mDate; }; #endif diff -r c7da699f0310 -r 2ad9a96518e3 ui/listutil.c --- a/ui/listutil.c Wed Feb 12 17:17:44 2014 +0000 +++ b/ui/listutil.c Wed Feb 12 18:45:13 2014 +0000 @@ -59,7 +59,7 @@ *data = (char*) malloc(*size); - if (data == NULL) { + if (*data == NULL) { printf("Malloc failed\n"); retval = UnknownError; goto cleanup; @@ -96,7 +96,7 @@ list_status_t readAndVerifyList(const char *fileName, char **data, size_t *size) { // int validSig = 0; - char ** firstChar = NULL; + char * signature = NULL; list_status_t retval = UnknownError; *data = NULL; @@ -111,14 +111,12 @@ if (!data || !*size) { // should not have happend if readList works as specified - printf ("No data or no size\n"); - printf ("%ld\n", (long)data); return UnknownError; } - firstChar = (char**) data; + signature = *data; - if (**firstChar != 'S') { + if (*signature != 'S') { printf("Does not start with S\n"); retval = InvalidFormat; goto cleanup; @@ -127,6 +125,8 @@ // TODO VERIFIY retval = Valid; +// Maybe check if all bytes are < 127 and > 0 + cleanup: if (retval != Valid && *data) { free(*data);