# HG changeset patch # User Andre Heinecke # Date 1395332444 0 # Node ID ba8a548ff25231f93358c064ed69b9457e0095e6 # Parent 1f27d6db5ee342b1f31387723a3a409507c44d91 Expand certificate class to make raw data accessible diff -r 1f27d6db5ee3 -r ba8a548ff252 ui/certificate.cpp --- a/ui/certificate.cpp Wed Mar 19 18:04:14 2014 +0000 +++ b/ui/certificate.cpp Thu Mar 20 16:20:44 2014 +0000 @@ -2,17 +2,17 @@ #include #include -const QString& Certificate::shortDescription() const { - return mShortDescription; -} - -Certificate::Certificate(const QByteArray& asn1data) : +Certificate::Certificate(const QString& b64Line) : mValid(false), mShortDescription(QObject::tr("Invalid Certificate")) { int ret = -1; char buf[2000]; + /* Cut of the first two chars (e.g. I: and decode) */ + QByteArray asn1data = QByteArray::fromBase64( + b64Line.right(b64Line.size() - 2).toLatin1()); + x509_crt_init(&mX509Cert); ret = x509_crt_parse(&mX509Cert, (const unsigned char*) asn1data.constData(), @@ -31,12 +31,15 @@ /* In case of success the return value is the size of the information * written into buf - * - * TODO: This is currently not short description but all x509 information * */ - mShortDescription = QString::fromUtf8(buf, ret); + + mDetails = QString::fromUtf8(buf, ret); + + mShortDescription = mDetails; /* TODO */ mValid = true; + + mBaseLine = b64Line; } Certificate::~Certificate() diff -r 1f27d6db5ee3 -r ba8a548ff252 ui/certificate.h --- a/ui/certificate.h Wed Mar 19 18:04:14 2014 +0000 +++ b/ui/certificate.h Thu Mar 20 16:20:44 2014 +0000 @@ -19,9 +19,14 @@ class Certificate { public: - /** @brief construct a certificate from an X509 ASN1 encoded byte array. + /** @brief construct a certificate from a line of a certificate list. + * + * The first two characters of the string are expected to be + * the command. I: or R: + * + * @param[in] b64Line The line from the certificate list. **/ - Certificate(const QByteArray& asn1data); + Certificate(const QString& b64Line); ~Certificate(); @@ -34,11 +39,30 @@ * for this certificate * **/ - const QString& shortDescription() const; + const QString& shortDescription() const {return mShortDescription;} + + /** @brief get details for the certificate + * + * Get the X509 information that is returned by x509_crt_info + * + **/ + const QString& details() const {return mDetails;} + + /** @brief get the line from which this certificate was constructed + * + * The resulting line includes the instruction e.g. + * + * I:BASE64ENCODEDATA... + * + **/ + const QString& base64Line() const {return mBaseLine;} private: bool mValid; + + QString mDetails; QString mShortDescription; + QString mBaseLine; x509_crt mX509Cert; };