Change QSslCertificate::toText() to return a QString.

A couple of people reviewing the toText() method (which is new in 5.0)
have said that since the string returned is human readable it should
be a QString not a QByteArray. This change follows their advice.

Change-Id: Ibade9a24870805f7fbe2d299abeb9c6e964f0cf4
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Richard Moore 2012-05-20 13:31:55 +01:00 committed by Qt by Nokia
parent 1f109a864b
commit 0b8021f5cb
4 changed files with 10 additions and 10 deletions

View File

@ -820,10 +820,10 @@ QByteArray QSslCertificate::toDer() const
\since 5.0
*/
QByteArray QSslCertificate::toText() const
QString QSslCertificate::toText() const
{
if (!d->x509)
return QByteArray();
return QString();
return d->text_from_X509(d->x509);
}
@ -991,17 +991,17 @@ QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::Encodi
return BEGINCERTSTRING "\n" + tmp + ENDCERTSTRING "\n";
}
QByteArray QSslCertificatePrivate::text_from_X509(X509 *x509)
QString QSslCertificatePrivate::text_from_X509(X509 *x509)
{
if (!x509) {
qWarning("QSslSocketBackendPrivate::text_from_X509: null X509");
return QByteArray();
return QString();
}
QByteArray result;
BIO *bio = q_BIO_new(q_BIO_s_mem());
if (!bio)
return result;
return QString();
q_X509_print(bio, x509);
@ -1013,7 +1013,7 @@ QByteArray QSslCertificatePrivate::text_from_X509(X509 *x509)
q_BIO_free(bio);
return result;
return QString::fromLatin1(result);
}
QByteArray QSslCertificatePrivate::asn1ObjectId(ASN1_OBJECT *object)

View File

@ -124,7 +124,7 @@ public:
QByteArray toPem() const;
QByteArray toDer() const;
QByteArray toText() const;
QString toText() const;
static QList<QSslCertificate> fromPath(
const QString &path, QSsl::EncodingFormat format = QSsl::Pem,

View File

@ -96,7 +96,7 @@ public:
static QByteArray asn1ObjectId(ASN1_OBJECT *object);
static QByteArray asn1ObjectName(ASN1_OBJECT *object);
static QByteArray QByteArray_from_X509(X509 *x509, QSsl::EncodingFormat format);
static QByteArray text_from_X509(X509 *x509);
static QString text_from_X509(X509 *x509);
static QSslCertificate QSslCertificate_from_X509(X509 *x509);
static QList<QSslCertificate> certificatesFromPem(const QByteArray &pem, int count = -1);
static QList<QSslCertificate> certificatesFromDer(const QByteArray &der, int count = -1);

View File

@ -859,7 +859,7 @@ void tst_QSslCertificate::toText()
QFile fNew(testDataDir + "/more-certificates/cert-large-expiration-date.txt.1.0.0");
QVERIFY(fNew.open(QIODevice::ReadOnly | QFile::Text));
QByteArray txtNew = fNew.readAll();
QVERIFY(txtOld == cert.toText() || txtNew == cert.toText());
QVERIFY(QString::fromLatin1(txtOld) == cert.toText() || QString::fromLatin1(txtNew) == cert.toText());
}
void tst_QSslCertificate::multipleCommonNames()
@ -1093,7 +1093,7 @@ public:
QList<QByteArray> subjectInfoAttributes;
QByteArray toDer;
QByteArray toPem;
QByteArray toText;
QString toText;
QByteArray version;
};