Const-correct a handful of time functions
See https://github.com/openssl/openssl/issues/21371
Change-Id: I4c2cf9a0f5cea1a65063d4a83c194b5e9eeb877c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61385
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
index a725d00..3c90fe8 100644
--- a/crypto/x509/x509_vfy.c
+++ b/crypto/x509/x509_vfy.c
@@ -1775,7 +1775,7 @@
return X509_cmp_time_posix(ctm, time(NULL));
}
-int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) {
+int X509_cmp_time(const ASN1_TIME *ctm, const time_t *cmp_time) {
int64_t compare_time = (cmp_time == NULL) ? time(NULL) : *cmp_time;
return X509_cmp_time_posix(ctm, compare_time);
}
@@ -1793,12 +1793,12 @@
return X509_time_adj(s, offset_sec, NULL);
}
-ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec, time_t *in_tm) {
+ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec, const time_t *in_tm) {
return X509_time_adj_ex(s, 0, offset_sec, in_tm);
}
ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, int offset_day, long offset_sec,
- time_t *in_tm) {
+ const time_t *in_tm) {
int64_t t = 0;
if (in_tm) {
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
index c41b3a5..c80b14e 100644
--- a/include/openssl/x509.h
+++ b/include/openssl/x509.h
@@ -1999,7 +1999,7 @@
//
// WARNING: Unlike most comparison functions, this function returns zero on
// error, not equality.
-OPENSSL_EXPORT int X509_cmp_time(const ASN1_TIME *s, time_t *t);
+OPENSSL_EXPORT int X509_cmp_time(const ASN1_TIME *s, const time_t *t);
// X509_cmp_time_posix compares |s| against |t|. On success, it returns a
// negative number if |s| <= |t| and a positive number if |s| > |t|. On error,
@@ -2015,12 +2015,12 @@
// X509_time_adj calls |X509_time_adj_ex| with |offset_day| equal to zero.
OPENSSL_EXPORT ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec,
- time_t *t);
+ const time_t *t);
// X509_time_adj_ex behaves like |ASN1_TIME_adj|, but adds an offset to |*t|. If
// |t| is NULL, it uses the current time instead of |*t|.
OPENSSL_EXPORT ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, int offset_day,
- long offset_sec, time_t *t);
+ long offset_sec, const time_t *t);
// X509_gmtime_adj behaves like |X509_time_adj_ex| but adds |offset_sec| to the
// current time.