X509_CMP_TIME(3)
π X509_CMP_TIME(3) π
okay so this is from the Library Functions Manual, and it's literally the ASN.1 Time utilities page β bestie, if you've ever needed to compare a certificate's time to right now or do some cursed little time-offset math, this is your girl πΈ
β¨ NAME β¨
X509_cmp_time, X509_cmp_current_time, X509_time_adj_ex, X509_time_adj, X509_gmtime_adj β ASN.1 Time utilities π
π SYNOPSIS π
library βlibcryptoβ #include <openssl/x509.h>
int
X509_cmp_time(const ASN1_TIME *asn1_time, time_t *cmp_time);
int
X509_cmp_current_time(const ASN1_TIME *asn1_time);
ASN1_TIME *
X509_time_adj_ex(ASN1_TIME *out_time, int offset_day, long offset_sec,
time_t *in_time);
ASN1_TIME *
X509_time_adj(ASN1_TIME *out_time, long offset_sec, time_t *in_time);
ASN1_TIME *
X509_gmtime_adj(ASN1_TIME *out_time, long offset_sec);
π¦ DESCRIPTION π¦
so here's the tea β β each of these does one specific little job, and honestly they're all serving:
X509_cmp_time()parsesasn1_timeand compares it tocmp_timeβ or, ifcmp_timeisNULL, it compares against the current time instead. iykyk πX509_cmp_current_time()compares it to the current time. that's it, that's the whole vibe.X509_time_adj_ex()setsout_timeto a time that isoffset_dayandoffset_seclater thanin_time. and listen βoffset_dayandoffset_seccan both be negative, which sets a time beforein_time. time travel works both directions bestie π alsooffset_secis allowed to exceed the number of seconds in a day, so don't stress about it overflowing your brain. ifin_timeisNULL, the current time gets used instead. and ifout_timeisNULL, a brand-newASN1_TIMEstructure is allocated and returned to you, like a lil gift πX509_time_adj()does the exact same thing, but with a0day offset. same energy, fewer args β¨X509_gmtime_adj()does the same thing but uses the current time instead ofin_timeβ so it setsout_timeto a timeoffset_secseconds later than the current time. very "now plus a bit" of it π°οΈ
π RETURN VALUES π
X509_cmp_time()andX509_cmp_current_time()return-1ifasn1_timeis earlier than or equal tocmp_time,1if it is later, or0on error. that0is giving "something went wrong, don't @ me" πX509_time_adj_ex(),X509_time_adj(), andX509_gmtime_adj()return a pointer to the updated or newly allocatedASN1_TIMEstructure β orNULLon error. so like, check it, bestie π«Ά
π SEE ALSO π
ASN1_TIME_new(3), ASN1_TIME_set(3), time(3)
go read those too, they're all part of the same friend group π
π§ HISTORY π§
X509_cmp_current_time()andX509_gmtime_adj()first appeared in SSLeay 0.6.0 and have been available since OpenBSD 2.4. vintage icons πX509_cmp_time()andX509_time_adj()first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9. era-defining honestly βX509_time_adj_ex()first appeared in OpenSSL 1.0.0 and has been available since OpenBSD 4.9. the newbie of the bunch π
ngl this whole page is short and sweet β but that-1/1/0return thing is highkey a trap, so like, read it twice before you ship π
and that's the whole page, bestie β brought to you by Debian, dated June 8, 2025 π mwah, go write some correct time comparisons π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2017, 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2017 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms