# HG changeset patch # User Andre Heinecke # Date 1395396410 0 # Node ID f1ebab8639dc3add97777fc97902e7aef130922f # Parent 0798b9e357251b19558a548f2b95b5ff7f3d11a1 Do not save the x509 cert as a member variable diff -r 0798b9e35725 -r f1ebab8639dc ui/certificate.cpp --- a/ui/certificate.cpp Fri Mar 21 09:48:46 2014 +0000 +++ b/ui/certificate.cpp Fri Mar 21 10:06:50 2014 +0000 @@ -2,27 +2,32 @@ #include #include +#include + Certificate::Certificate(const QString& b64Line) : mValid(false), mShortDescription(QObject::tr("Invalid Certificate")) { int ret = -1; char buf[2000]; + x509_crt x509cert; /* 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, + x509_crt_init(&x509cert); + ret = x509_crt_parse(&x509cert, (const unsigned char*) asn1data.constData(), asn1data.size()); if (ret != 0) { qDebug() << "Parsing certificate failed with error: " << ret; + x509_crt_free(&x509cert); return; } - ret = x509_crt_info(buf, 2000, "", &mX509Cert); + ret = x509_crt_info(buf, 2000, "", &x509cert); + x509_crt_free(&x509cert); if (ret <= 0) { qDebug() << "Getting certificate info failed with error: " << ret; @@ -41,8 +46,3 @@ mBaseLine = b64Line; } - -Certificate::~Certificate() -{ - x509_crt_free(&mX509Cert); -} diff -r 0798b9e35725 -r f1ebab8639dc ui/certificate.h --- a/ui/certificate.h Fri Mar 21 09:48:46 2014 +0000 +++ b/ui/certificate.h Fri Mar 21 10:06:50 2014 +0000 @@ -14,11 +14,10 @@ #include #endif -#include - class Certificate { public: + /** @brief construct a certificate from a line of a certificate list. * * The first two characters of the string are expected to be @@ -26,9 +25,7 @@ * * @param[in] b64Line The line from the certificate list. **/ - Certificate(const QString& b64Line); - - ~Certificate(); + Certificate(const QString& b64Line = QString()); /** @brief check if this certificate could be parsed */ bool isValid() const {return mValid;} @@ -63,7 +60,5 @@ QString mDetails; QString mShortDescription; QString mBaseLine; - - x509_crt mX509Cert; }; #endif