Port autotest to QRegularExpression
Change-Id: Id632ed191add8beab6a857c4c949cc78e4c5eccf Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
21a9b67cdb
commit
986cfe312e
@ -126,24 +126,25 @@ void tst_QSslCertificate::initTestCase()
|
|||||||
|
|
||||||
QDir dir(testDataDir + "certificates");
|
QDir dir(testDataDir + "certificates");
|
||||||
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
|
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
|
||||||
QRegExp rxCert(QLatin1String("^.+\\.(pem|der)$"));
|
QRegularExpression rxCert(QLatin1String("^.+\\.(pem|der)$"));
|
||||||
QRegExp rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
|
QRegularExpression rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
|
||||||
QRegExp rxPubKey(QLatin1String("^(.+\\.(?:pem|der))\\.pubkey$"));
|
QRegularExpression rxPubKey(QLatin1String("^(.+\\.(?:pem|der))\\.pubkey$"));
|
||||||
QRegExp rxDigest(QLatin1String("^(.+\\.(?:pem|der))\\.digest-(md5|sha1)$"));
|
QRegularExpression rxDigest(QLatin1String("^(.+\\.(?:pem|der))\\.digest-(md5|sha1)$"));
|
||||||
|
QRegularExpressionMatch match;
|
||||||
foreach (QFileInfo fileInfo, fileInfoList) {
|
foreach (QFileInfo fileInfo, fileInfoList) {
|
||||||
if (rxCert.indexIn(fileInfo.fileName()) >= 0)
|
if ((match = rxCert.match(fileInfo.fileName())).hasMatch())
|
||||||
certInfoList <<
|
certInfoList <<
|
||||||
CertInfo(fileInfo,
|
CertInfo(fileInfo,
|
||||||
rxCert.cap(1) == QLatin1String("pem") ? QSsl::Pem : QSsl::Der);
|
match.captured(1) == QLatin1String("pem") ? QSsl::Pem : QSsl::Der);
|
||||||
if (rxSan.indexIn(fileInfo.fileName()) >= 0)
|
if ((match = rxSan.match(fileInfo.fileName())).hasMatch())
|
||||||
subjAltNameMap.insert(rxSan.cap(1), fileInfo.absoluteFilePath());
|
subjAltNameMap.insert(match.captured(1), fileInfo.absoluteFilePath());
|
||||||
if (rxPubKey.indexIn(fileInfo.fileName()) >= 0)
|
if ((match = rxPubKey.match(fileInfo.fileName())).hasMatch())
|
||||||
pubkeyMap.insert(rxPubKey.cap(1), fileInfo.absoluteFilePath());
|
pubkeyMap.insert(match.captured(1), fileInfo.absoluteFilePath());
|
||||||
if (rxDigest.indexIn(fileInfo.fileName()) >= 0) {
|
if ((match = rxDigest.match(fileInfo.fileName())).hasMatch()) {
|
||||||
if (rxDigest.cap(2) == QLatin1String("md5"))
|
if (match.captured(2) == QLatin1String("md5"))
|
||||||
md5Map.insert(rxDigest.cap(1), fileInfo.absoluteFilePath());
|
md5Map.insert(match.captured(1), fileInfo.absoluteFilePath());
|
||||||
else
|
else
|
||||||
sha1Map.insert(rxDigest.cap(1), fileInfo.absoluteFilePath());
|
sha1Map.insert(match.captured(1), fileInfo.absoluteFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,11 +339,12 @@ void tst_QSslCertificate::digest_data()
|
|||||||
static QByteArray convertDigest(const QByteArray &input)
|
static QByteArray convertDigest(const QByteArray &input)
|
||||||
{
|
{
|
||||||
QByteArray result;
|
QByteArray result;
|
||||||
QRegExp rx(QLatin1String("(?:=|:)([0-9A-Fa-f]{2})"));
|
QRegularExpression rx(QLatin1String("(?:=|:)([0-9A-Fa-f]{2})"));
|
||||||
|
QRegularExpressionMatch match;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
while ((pos = rx.indexIn(input, pos)) != -1) {
|
while ((match = rx.match(input, pos)).hasMatch()) {
|
||||||
result.append(rx.cap(1).toLatin1());
|
result.append(match.captured(1).toLatin1());
|
||||||
pos += rx.matchedLength();
|
pos = match.capturedEnd();
|
||||||
}
|
}
|
||||||
return QByteArray::fromHex(result);
|
return QByteArray::fromHex(result);
|
||||||
}
|
}
|
||||||
@ -418,16 +420,17 @@ void tst_QSslCertificate::subjectAlternativeNames()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// verify that each entry in fileContents is present in subjAltNames
|
// verify that each entry in fileContents is present in subjAltNames
|
||||||
QRegExp rx(QLatin1String("(email|DNS):([^,\\r\\n]+)"));
|
QRegularExpression rx(QLatin1String("(email|DNS):([^,\\r\\n]+)"));
|
||||||
for (int pos = 0; (pos = rx.indexIn(fileContents, pos)) != -1; pos += rx.matchedLength()) {
|
QRegularExpressionMatch match;
|
||||||
|
for (int pos = 0; (match = rx.match(fileContents, pos)).hasMatch(); pos = match.capturedEnd()) {
|
||||||
QSsl::AlternativeNameEntryType key;
|
QSsl::AlternativeNameEntryType key;
|
||||||
if (rx.cap(1) == QLatin1String("email"))
|
if (match.captured(1) == QLatin1String("email"))
|
||||||
key = QSsl::EmailEntry;
|
key = QSsl::EmailEntry;
|
||||||
else if (rx.cap(1) == QLatin1String("DNS"))
|
else if (match.captured(1) == QLatin1String("DNS"))
|
||||||
key = QSsl::DnsEntry;
|
key = QSsl::DnsEntry;
|
||||||
else
|
else
|
||||||
QFAIL("unsupported alternative name type");
|
QFAIL("unsupported alternative name type");
|
||||||
QVERIFY(altSubjectNames.contains(key, rx.cap(2)));
|
QVERIFY(altSubjectNames.contains(key, match.captured(2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user