QSslEllipticCurve: add fromLongName
Since the conversion to a long name was already there, also support creation from a long name. Change-Id: Iad712db7447fb0a0a18f600b7db54da5b5b87154 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
309c804239
commit
2ec2dbed67
|
|
@ -92,6 +92,19 @@ QT_BEGIN_NAMESPACE
|
|||
\sa shortName()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QSslEllipticCurve QSslEllipticCurve::fromLongName(const QString &name)
|
||||
|
||||
Returns an QSslEllipticCurve instance representing the named curve \a name.
|
||||
The \a name is a long name for the curve, whose exact spelling depends on the
|
||||
SSL implementation.
|
||||
|
||||
If the given \a name is not supported, returns an invalid QSslEllipticCurve instance.
|
||||
|
||||
\note The OpenSSL implementation of this function treats the name case-sensitively.
|
||||
|
||||
\sa longName()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString QSslEllipticCurve::shortName() const
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public:
|
|||
}
|
||||
|
||||
Q_NETWORK_EXPORT static QSslEllipticCurve fromShortName(const QString &name);
|
||||
Q_NETWORK_EXPORT static QSslEllipticCurve fromLongName(const QString &name);
|
||||
|
||||
Q_NETWORK_EXPORT QString shortName() const Q_REQUIRED_RESULT;
|
||||
Q_NETWORK_EXPORT QString longName() const Q_REQUIRED_RESULT;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@ QSslEllipticCurve QSslEllipticCurve::fromShortName(const QString &name)
|
|||
return QSslEllipticCurve();
|
||||
}
|
||||
|
||||
QSslEllipticCurve QSslEllipticCurve::fromLongName(const QString &name)
|
||||
{
|
||||
Q_UNUSED(name);
|
||||
return QSslEllipticCurve();
|
||||
}
|
||||
|
||||
bool QSslEllipticCurve::isTlsNamedCurve() const
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -103,6 +103,26 @@ QSslEllipticCurve QSslEllipticCurve::fromShortName(const QString &name)
|
|||
return result;
|
||||
}
|
||||
|
||||
QSslEllipticCurve QSslEllipticCurve::fromLongName(const QString &name)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return QSslEllipticCurve();
|
||||
|
||||
QSslSocketPrivate::ensureInitialized();
|
||||
|
||||
QSslEllipticCurve result;
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
const QByteArray curveNameLatin1 = name.toLatin1();
|
||||
|
||||
int nid = q_OBJ_ln2nid(curveNameLatin1.data());
|
||||
result.id = nid;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// The brainpool curve NIDs (RFC 7027) have been introduced in OpenSSL 1.0.2,
|
||||
// redefine them here to make Qt compile with previous versions of OpenSSL
|
||||
// (yet correctly recognize them as TLS named curves).
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ DEFINEFUNC2(int, i2d_X509, X509 *a, a, unsigned char **b, b, return -1, return)
|
|||
DEFINEFUNC(const char *, OBJ_nid2sn, int a, a, return 0, return)
|
||||
DEFINEFUNC(const char *, OBJ_nid2ln, int a, a, return 0, return)
|
||||
DEFINEFUNC(int, OBJ_sn2nid, const char *s, s, return 0, return)
|
||||
DEFINEFUNC(int, OBJ_ln2nid, const char *s, s, return 0, return)
|
||||
DEFINEFUNC3(int, i2t_ASN1_OBJECT, char *a, a, int b, b, ASN1_OBJECT *c, c, return -1, return)
|
||||
DEFINEFUNC4(int, OBJ_obj2txt, char *a, a, int b, b, ASN1_OBJECT *c, c, int d, d, return -1, return)
|
||||
|
||||
|
|
@ -774,6 +775,7 @@ bool q_resolveOpenSslSymbols()
|
|||
RESOLVEFUNC(OBJ_nid2sn)
|
||||
RESOLVEFUNC(OBJ_nid2ln)
|
||||
RESOLVEFUNC(OBJ_sn2nid)
|
||||
RESOLVEFUNC(OBJ_ln2nid)
|
||||
RESOLVEFUNC(i2t_ASN1_OBJECT)
|
||||
RESOLVEFUNC(OBJ_obj2txt)
|
||||
RESOLVEFUNC(OBJ_obj2nid)
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ int q_i2d_X509(X509 *a, unsigned char **b);
|
|||
const char *q_OBJ_nid2sn(int a);
|
||||
const char *q_OBJ_nid2ln(int a);
|
||||
int q_OBJ_sn2nid(const char *s);
|
||||
int q_OBJ_ln2nid(const char *s);
|
||||
int q_i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *obj);
|
||||
int q_OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *obj, int no_name);
|
||||
int q_OBJ_obj2nid(const ASN1_OBJECT *a);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ private Q_SLOTS:
|
|||
void construction();
|
||||
void fromShortName_data();
|
||||
void fromShortName();
|
||||
void fromLongName_data();
|
||||
void fromLongName();
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -114,6 +116,34 @@ void tst_QSslEllipticCurve::fromShortName()
|
|||
QCOMPARE(result.shortName(), valid ? shortName : QString());
|
||||
}
|
||||
|
||||
void tst_QSslEllipticCurve::fromLongName_data()
|
||||
{
|
||||
QTest::addColumn<QString>("longName");
|
||||
QTest::addColumn<QSslEllipticCurve>("curve");
|
||||
QTest::addColumn<bool>("valid");
|
||||
|
||||
QTest::newRow("QString()") << QString() << QSslEllipticCurve() << false;
|
||||
QTest::newRow("\"\"") << QString("") << QSslEllipticCurve() << false;
|
||||
QTest::newRow("does-not-exist") << QStringLiteral("does-not-exist") << QSslEllipticCurve() << false;
|
||||
Q_FOREACH (QSslEllipticCurve ec, QSslSocket::supportedEllipticCurves()) {
|
||||
const QString lN = ec.longName();
|
||||
QTest::newRow(qPrintable("supported EC \"" + lN + '"')) << lN << ec << true;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSslEllipticCurve::fromLongName()
|
||||
{
|
||||
QFETCH(QString, longName);
|
||||
QFETCH(QSslEllipticCurve, curve);
|
||||
QFETCH(bool, valid);
|
||||
|
||||
const QSslEllipticCurve result = QSslEllipticCurve::fromLongName(longName);
|
||||
QCOMPARE(result, curve);
|
||||
QCOMPARE(result.isValid(), valid);
|
||||
QCOMPARE(result.longName(), curve.longName());
|
||||
QCOMPARE(result.longName(), valid ? longName : QString());
|
||||
}
|
||||
|
||||
#endif // QT_NO_SSL
|
||||
|
||||
QTEST_MAIN(tst_QSslEllipticCurve)
|
||||
|
|
|
|||
Loading…
Reference in New Issue