diff --git a/src/plugins/tls/shared/qasn1element.cpp b/src/plugins/tls/shared/qasn1element.cpp index 8d4d908e534..97be46866d1 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; diff --git a/tests/auto/network/ssl/qasn1element/tst_qasn1element.cpp b/tests/auto/network/ssl/qasn1element/tst_qasn1element.cpp index 75170b03b42..54af3b39241 100644 --- a/tests/auto/network/ssl/qasn1element/tst_qasn1element.cpp +++ b/tests/auto/network/ssl/qasn1element/tst_qasn1element.cpp @@ -166,9 +166,6 @@ void tst_QAsn1Element::dateTime() QAsn1Element elem; QVERIFY(elem.read(encoded)); - QEXPECT_FAIL("UTCTime - leap day year 2000", - "We decode as 1900, and then adjust to 2000. But there was no leap day in 1900!", - Continue); QCOMPARE(elem.toDateTime(), value); }