view ui/certificatelist.cpp @ 27:62cd56cea09b

Start on polarssl Downloader. This breaks the windows build for now
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 12 Mar 2014 16:15:52 +0100
parents dc1e1e9e62ce
children 37fc66967517
line wrap: on
line source
#include "certificatelist.h"

#include <QDebug>

#define PARSER_VERSION "1"

CertificateList::CertificateList(const char *fileName)
{
    char *data = NULL;
    size_t size = 0;

    mStatus = readAndVerifyList(fileName, &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 << Certificate(
                    QByteArray::fromBase64(curLine.remove(0,2).toLatin1()));
        } else if (curLine.startsWith("R:")) {
            mCertificatesInstall << Certificate(
                    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;
        }
    }
}

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