comparison ui/certificatelist.cpp @ 9:2ad9a96518e3

Actually parse all elements in the list
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 12 Feb 2014 18:45:13 +0000
parents 992c0ec57660
children dc1e1e9e62ce
comparison
equal deleted inserted replaced
8:c7da699f0310 9:2ad9a96518e3
1 #include "certificatelist.h" 1 #include "certificatelist.h"
2 2
3 #include <QDebug> 3 #include <QDebug>
4
5 #define PARSER_VERSION "1"
4 6
5 CertificateList::CertificateList(const char *fileName) 7 CertificateList::CertificateList(const char *fileName)
6 { 8 {
7 char *data = NULL; 9 char *data = NULL;
8 size_t size = 0; 10 size_t size = 0;
9 11
10 mStatus = readAndVerifyList(fileName, &data, &size); 12 mStatus = readAndVerifyList(fileName, &data, &size);
11 13
12 if (isValid()) { 14 if (!isValid()) {
13 mFileContent = QByteArray::fromRawData(data, size); 15 return;
16 }
17
18 // Take the data into the Qt Universe where memory is plentiful
19 // and CPU's are fast :)
20 QStringList lines = QString::fromLatin1(data, size).split("\n");
21 free(data);
22 data = NULL;
23
24 for (int i = 0; i < lines.size(); ++i) {
25 QString curLine = lines[i].trimmed();
26 if (curLine.startsWith("F:")) {
27 if (curLine.right(1) != PARSER_VERSION) {
28 qDebug() << "Invalid Format Version";
29 mStatus = IncompatibleVersion;
30 return;
31 }
32 } else if (curLine.startsWith("D:")) {
33 bool ok = false;
34 qlonglong timestamp = 0;
35
36 curLine.remove(0, 2);
37 timestamp = curLine.toLongLong(&ok);
38 if (!ok) {
39 qDebug() << "Invalid Date";
40 mStatus = InvalidFormat;
41 return;
42 }
43
44 mDate = QDateTime::fromMSecsSinceEpoch(timestamp * 1000);
45 } else if (curLine.startsWith("I:")) {
46 mCertificatesInstall << QByteArray::fromBase64(curLine.remove(0,2).toLatin1());
47 } else if (curLine.startsWith("R:")) {
48 mCertificatesInstall << QByteArray::fromBase64(curLine.remove(0,2).toLatin1());
49 } else if (curLine.startsWith("S:")) {
50 // Signature is verified in readAndVerifyList
51 continue;
52 } else if (!curLine.isEmpty()){
53 qDebug () << "Don't know how to handle: " << curLine;
54 }
14 } 55 }
15 } 56 }

http://wald.intevation.org/projects/trustbridge/