summaryrefslogtreecommitdiffstats
path: root/src/plugins/tls/shared
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-11-09 17:25:01 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2023-12-08 11:40:37 +0100
commit9bf7d2a76a26e2f5d25e4c6eb9c27cdfeebd3f66 (patch)
treed2135dc7a46e3308e7fc41687f61a4d469c4d91a /src/plugins/tls/shared
parent41f84f3ddb780ec751e3fc706dd242fc4a99de7a (diff)
Adapt ASN.1 datetime parsing to use the new century control
It previously had to kludge a 1900-to-1999 date into a 1950-to-2049 range; it can now tell QDTP to do that for it. In particular, this fixes a problem with 00-02-29, which failed to parse using 1900 as base year so couldn't be corrected to 2000-02-29, which is now the date it finds directly. Task-number: QTBUG-46843 Change-Id: I7ac936bdfb15b78daed5d237c5d921c800af4951 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/plugins/tls/shared')
-rw-r--r--src/plugins/tls/shared/qasn1element.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/plugins/tls/shared/qasn1element.cpp b/src/plugins/tls/shared/qasn1element.cpp
index 8d4d908e53..97be46866d 100644
--- a/src/plugins/tls/shared/qasn1element.cpp
+++ b/src/plugins/tls/shared/qasn1element.cpp
@@ -225,31 +225,28 @@ QDateTime QAsn1Element::toDateTime() const
return result;
if (mType == UtcTimeType && mValue.size() == 13) {
- const QLatin1StringView inputView(mValue);
- QDate date = QDate::fromString(inputView.first(6), u"yyMMdd");
- if (!date.isValid())
- return result;
// RFC 2459:
// Where YY is greater than or equal to 50, the year shall be
// interpreted as 19YY; and
//
// Where YY is less than 50, the year shall be interpreted as 20YY.
//
- // QDateTime interprets the 'yy' format as 19yy, so we may need to adjust
- // the year (bring it in the [1950, 2049] range).
- if (date.year() < 1950)
- date = date.addYears(100);
+ // so use 1950 as base year.
+ constexpr int rfc2459CenturyStart = 1950;
+ const QLatin1StringView inputView(mValue);
+ QDate date = QDate::fromString(inputView.first(6), u"yyMMdd", rfc2459CenturyStart);
+ if (!date.isValid())
+ return result;
- Q_ASSERT(date.year() >= 1950);
- Q_ASSERT(date.year() <= 2049);
+ Q_ASSERT(date.year() >= rfc2459CenturyStart);
+ Q_ASSERT(date.year() < 100 + rfc2459CenturyStart);
QTime time = QTime::fromString(inputView.sliced(6, 6), u"HHmmss");
if (!time.isValid())
return result;
result = QDateTime(date, time, QTimeZone::UTC);
} else if (mType == GeneralizedTimeType && mValue.size() == 15) {
- result = QDateTime::fromString(QString::fromLatin1(mValue),
- u"yyyyMMddHHmmsst");
+ result = QDateTime::fromString(QString::fromLatin1(mValue), u"yyyyMMddHHmmsst");
}
return result;