From 6e8adf5287af7fef7c401c09fb8642029e6daec1 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Tue, 21 Jan 2025 11:51:15 -0500 Subject: [PATCH] Remove ASN1_UTCTIME_cmp_time_t This does not seem to be used anywhere, and for good reason: it only works on UTCTime, so it will break with any dates past 2050, which need GeneralizedTime. We don't have the ASN1_TIME and ASN1_GENERALIZEDTIME versions. They seem to have been added a bit later. (If we ever need to add these back, we should probably change the input type to int64_t, but for now we don't seem to need them at all.) Update-Note: Removed an unused function. Change-Id: I23c9f0b41d210f3a44122165331389b30d6ecab0 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75408 Commit-Queue: David Benjamin Auto-Submit: David Benjamin Commit-Queue: Bob Beck Reviewed-by: Bob Beck --- crypto/asn1/a_utctm.cc | 31 ------------------------------- crypto/asn1/asn1_test.cc | 8 ++------ include/openssl/asn1.h | 4 ---- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/crypto/asn1/a_utctm.cc b/crypto/asn1/a_utctm.cc index 993dd5d21..14be46123 100644 --- a/crypto/asn1/a_utctm.cc +++ b/crypto/asn1/a_utctm.cc @@ -102,34 +102,3 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, s->type = V_ASN1_UTCTIME; return s; } - -int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) { - struct tm stm, ttm; - int day, sec; - - if (!asn1_utctime_to_tm(&stm, s, /*allow_timezone_offset=*/1)) { - return -2; - } - - if (!OPENSSL_posix_to_tm(t, &ttm)) { - return -2; - } - - if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm)) { - return -2; - } - - if (day > 0) { - return 1; - } - if (day < 0) { - return -1; - } - if (sec > 0) { - return 1; - } - if (sec < 0) { - return -1; - } - return 0; -} diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc index 870de3850..8508fc147 100644 --- a/crypto/asn1/asn1_test.cc +++ b/crypto/asn1/asn1_test.cc @@ -1169,7 +1169,7 @@ TEST(ASN1Test, UTCTimeZoneOffsets) { EXPECT_EQ(V_ASN1_UTCTIME, ASN1_STRING_type(s.get())); EXPECT_EQ("700101000000Z", ASN1StringToStringView(s.get())); - // UTCTIME_set_string should not allow a timezeone offset + // UTCTIME_set_string should not allow a timezone offset EXPECT_FALSE(ASN1_UTCTIME_set_string(s.get(), "700101000000-0400")); // Forcibly construct a utc time with a timezone offset. @@ -1178,13 +1178,9 @@ TEST(ASN1Test, UTCTimeZoneOffsets) { EXPECT_EQ(V_ASN1_UTCTIME, ASN1_STRING_type(s.get())); EXPECT_EQ("700101000000-0400", ASN1StringToStringView(s.get())); - // check is expected to be valid with timezeone offsets + // check is expected to be valid with timezone offsets ASSERT_TRUE(ASN1_UTCTIME_check(s.get())); - // cmp_time_t allows timezeone offset, and we are expected to be 4 hours - // behind the epoch. - EXPECT_EQ(ASN1_UTCTIME_cmp_time_t(s.get(), (4 * 60 * 60 * -1)), 0); - int64_t posix_time; EXPECT_FALSE(ASN1_TIME_to_posix(s.get(), &posix_time)); ASSERT_TRUE(ASN1_TIME_to_posix_nonstandard(s.get(), &posix_time)); diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h index 57cdf6c06..4a1877ac4 100644 --- a/include/openssl/asn1.h +++ b/include/openssl/asn1.h @@ -1181,10 +1181,6 @@ OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, // If |s| is NULL, this function validates |str| without copying it. OPENSSL_EXPORT int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); -// ASN1_UTCTIME_cmp_time_t compares |s| to |t|. It returns -1 if |s| < |t|, 0 if -// they are equal, 1 if |s| > |t|, and -2 on error. -OPENSSL_EXPORT int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); - // ASN1_GENERALIZEDTIME_new calls |ASN1_STRING_type_new| with // |V_ASN1_GENERALIZEDTIME|. The resulting object contains empty contents and // must be initialized to be a valid GeneralizedTime.