ASN1_TIME_set.3ossl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "ASN1_TIME_SET 3ossl"
  136. .TH ASN1_TIME_SET 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. ASN1_TIME_set, ASN1_UTCTIME_set, ASN1_GENERALIZEDTIME_set,
  143. ASN1_TIME_adj, ASN1_UTCTIME_adj, ASN1_GENERALIZEDTIME_adj,
  144. ASN1_TIME_check, ASN1_UTCTIME_check, ASN1_GENERALIZEDTIME_check,
  145. ASN1_TIME_set_string, ASN1_UTCTIME_set_string, ASN1_GENERALIZEDTIME_set_string,
  146. ASN1_TIME_set_string_X509,
  147. ASN1_TIME_normalize,
  148. ASN1_TIME_to_tm,
  149. ASN1_TIME_print, ASN1_TIME_print_ex, ASN1_UTCTIME_print, ASN1_GENERALIZEDTIME_print,
  150. ASN1_TIME_diff,
  151. ASN1_TIME_cmp_time_t, ASN1_UTCTIME_cmp_time_t,
  152. ASN1_TIME_compare,
  153. ASN1_TIME_to_generalizedtime,
  154. ASN1_TIME_dup, ASN1_UTCTIME_dup, ASN1_GENERALIZEDTIME_dup \- ASN.1 Time functions
  155. .SH "SYNOPSIS"
  156. .IX Header "SYNOPSIS"
  157. .Vb 4
  158. \& ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
  159. \& ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
  160. \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
  161. \& time_t t);
  162. \&
  163. \& ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day,
  164. \& long offset_sec);
  165. \& ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
  166. \& int offset_day, long offset_sec);
  167. \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
  168. \& time_t t, int offset_day,
  169. \& long offset_sec);
  170. \&
  171. \& int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
  172. \& int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
  173. \& int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
  174. \& int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s,
  175. \& const char *str);
  176. \&
  177. \& int ASN1_TIME_normalize(ASN1_TIME *s);
  178. \&
  179. \& int ASN1_TIME_check(const ASN1_TIME *t);
  180. \& int ASN1_UTCTIME_check(const ASN1_UTCTIME *t);
  181. \& int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *t);
  182. \&
  183. \& int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
  184. \& int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags);
  185. \& int ASN1_UTCTIME_print(BIO *b, const ASN1_UTCTIME *s);
  186. \& int ASN1_GENERALIZEDTIME_print(BIO *b, const ASN1_GENERALIZEDTIME *s);
  187. \&
  188. \& int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
  189. \& int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from,
  190. \& const ASN1_TIME *to);
  191. \&
  192. \& int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
  193. \& int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
  194. \&
  195. \& int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
  196. \&
  197. \& ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
  198. \& ASN1_GENERALIZEDTIME **out);
  199. \&
  200. \& ASN1_TIME *ASN1_TIME_dup(const ASN1_TIME *t);
  201. \& ASN1_UTCTIME *ASN1_UTCTIME_dup(const ASN1_UTCTIME *t);
  202. \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_dup(const ASN1_GENERALIZEDTIME *t);
  203. .Ve
  204. .SH "DESCRIPTION"
  205. .IX Header "DESCRIPTION"
  206. The \fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR and \fBASN1_GENERALIZEDTIME_set()\fR
  207. functions set the structure \fIs\fR to the time represented by the time_t
  208. value \fIt\fR. If \fIs\fR is \s-1NULL\s0 a new time structure is allocated and returned.
  209. .PP
  210. The \fBASN1_TIME_adj()\fR, \fBASN1_UTCTIME_adj()\fR and \fBASN1_GENERALIZEDTIME_adj()\fR
  211. functions set the time structure \fIs\fR to the time represented
  212. by the time \fIoffset_day\fR and \fIoffset_sec\fR after the time_t value \fIt\fR.
  213. The values of \fIoffset_day\fR or \fIoffset_sec\fR can be negative to set a
  214. time before \fIt\fR. The \fIoffset_sec\fR value can also exceed the number of
  215. seconds in a day. If \fIs\fR is \s-1NULL\s0 a new structure is allocated
  216. and returned.
  217. .PP
  218. The \fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR and
  219. \&\fBASN1_GENERALIZEDTIME_set_string()\fR functions set the time structure \fIs\fR
  220. to the time represented by string \fIstr\fR which must be in appropriate \s-1ASN.1\s0
  221. time format (for example \s-1YYMMDDHHMMSSZ\s0 or \s-1YYYYMMDDHHMMSSZ\s0). If \fIs\fR is \s-1NULL\s0
  222. this function performs a format check on \fIstr\fR only. The string \fIstr\fR
  223. is copied into \fIs\fR.
  224. .PP
  225. \&\fBASN1_TIME_set_string_X509()\fR sets \fB\s-1ASN1_TIME\s0\fR structure \fIs\fR to the time
  226. represented by string \fIstr\fR which must be in appropriate time format
  227. that \s-1RFC 5280\s0 requires, which means it only allows \s-1YYMMDDHHMMSSZ\s0 and
  228. \&\s-1YYYYMMDDHHMMSSZ\s0 (leap second is rejected), all other \s-1ASN.1\s0 time format
  229. are not allowed. If \fIs\fR is \s-1NULL\s0 this function performs a format check
  230. on \fIstr\fR only.
  231. .PP
  232. The \fBASN1_TIME_normalize()\fR function converts an \fB\s-1ASN1_GENERALIZEDTIME\s0\fR or
  233. \&\fB\s-1ASN1_UTCTIME\s0\fR into a time value that can be used in a certificate. It
  234. should be used after the \fBASN1_TIME_set_string()\fR functions and before
  235. \&\fBASN1_TIME_print()\fR functions to get consistent (i.e. \s-1GMT\s0) results.
  236. .PP
  237. The \fBASN1_TIME_check()\fR, \fBASN1_UTCTIME_check()\fR and \fBASN1_GENERALIZEDTIME_check()\fR
  238. functions check the syntax of the time structure \fIs\fR.
  239. .PP
  240. The \fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
  241. functions print the time structure \fIs\fR to \s-1BIO\s0 \fIb\fR in human readable
  242. format. It will be of the format \s-1MMM DD HH:MM:SS YYYY\s0 [\s-1GMT\s0], for example
  243. \&\*(L"Feb 3 00:55:52 2015 \s-1GMT\*(R",\s0 which does not include a newline.
  244. If the time structure has invalid format it prints out \*(L"Bad time value\*(R" and
  245. returns an error. The output for generalized time may include a fractional part
  246. following the second.
  247. .PP
  248. \&\fBASN1_TIME_print_ex()\fR provides \fIflags\fR to specify the output format of the
  249. datetime. This can be either \fB\s-1ASN1_DTFLGS_RFC822\s0\fR or \fB\s-1ASN1_DTFLGS_ISO8601\s0\fR.
  250. .PP
  251. \&\fBASN1_TIME_to_tm()\fR converts the time \fIs\fR to the standard \fItm\fR structure.
  252. If \fIs\fR is \s-1NULL,\s0 then the current time is converted. The output time is \s-1GMT.\s0
  253. The \fItm_sec\fR, \fItm_min\fR, \fItm_hour\fR, \fItm_mday\fR, \fItm_wday\fR, \fItm_yday\fR,
  254. \&\fItm_mon\fR and \fItm_year\fR fields of \fItm\fR structure are set to proper values,
  255. whereas all other fields are set to 0. If \fItm\fR is \s-1NULL\s0 this function performs
  256. a format check on \fIs\fR only. If \fIs\fR is in Generalized format with fractional
  257. seconds, e.g. \s-1YYYYMMDDHHMMSS.SSSZ,\s0 the fractional seconds will be lost while
  258. converting \fIs\fR to \fItm\fR structure.
  259. .PP
  260. \&\fBASN1_TIME_diff()\fR sets \fI*pday\fR and \fI*psec\fR to the time difference between
  261. \&\fIfrom\fR and \fIto\fR. If \fIto\fR represents a time later than \fIfrom\fR then
  262. one or both (depending on the time difference) of \fI*pday\fR and \fI*psec\fR
  263. will be positive. If \fIto\fR represents a time earlier than \fIfrom\fR then
  264. one or both of \fI*pday\fR and \fI*psec\fR will be negative. If \fIto\fR and \fIfrom\fR
  265. represent the same time then \fI*pday\fR and \fI*psec\fR will both be zero.
  266. If both \fI*pday\fR and \fI*psec\fR are nonzero they will always have the same
  267. sign. The value of \fI*psec\fR will always be less than the number of seconds
  268. in a day. If \fIfrom\fR or \fIto\fR is \s-1NULL\s0 the current time is used.
  269. .PP
  270. The \fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR functions compare
  271. the two times represented by the time structure \fIs\fR and the time_t \fIt\fR.
  272. .PP
  273. The \fBASN1_TIME_compare()\fR function compares the two times represented by the
  274. time structures \fIa\fR and \fIb\fR.
  275. .PP
  276. The \fBASN1_TIME_to_generalizedtime()\fR function converts an \fB\s-1ASN1_TIME\s0\fR to an
  277. \&\fB\s-1ASN1_GENERALIZEDTIME\s0\fR, regardless of year. If either \fIout\fR or
  278. \&\fI*out\fR are \s-1NULL,\s0 then a new object is allocated and must be freed after use.
  279. .PP
  280. The \fBASN1_TIME_dup()\fR, \fBASN1_UTCTIME_dup()\fR and \fBASN1_GENERALIZEDTIME_dup()\fR functions
  281. duplicate the time structure \fIt\fR and return the duplicated result
  282. correspondingly.
  283. .SH "NOTES"
  284. .IX Header "NOTES"
  285. The \fB\s-1ASN1_TIME\s0\fR structure corresponds to the \s-1ASN.1\s0 structure \fBTime\fR
  286. defined in \s-1RFC5280\s0 et al. The time setting functions obey the rules outlined
  287. in \s-1RFC5280:\s0 if the date can be represented by UTCTime it is used, else
  288. GeneralizedTime is used.
  289. .PP
  290. The \fB\s-1ASN1_TIME\s0\fR, \fB\s-1ASN1_UTCTIME\s0\fR and \fB\s-1ASN1_GENERALIZEDTIME\s0\fR structures are
  291. represented as an \fB\s-1ASN1_STRING\s0\fR internally and can be freed up using
  292. \&\fBASN1_STRING_free()\fR.
  293. .PP
  294. The \fB\s-1ASN1_TIME\s0\fR structure can represent years from 0000 to 9999 but no attempt
  295. is made to correct ancient calendar changes (for example from Julian to
  296. Gregorian calendars).
  297. .PP
  298. \&\fB\s-1ASN1_UTCTIME\s0\fR is limited to a year range of 1950 through 2049.
  299. .PP
  300. Some applications add offset times directly to a time_t value and pass the
  301. results to \fBASN1_TIME_set()\fR (or equivalent). This can cause problems as the
  302. time_t value can overflow on some systems resulting in unexpected results.
  303. New applications should use \fBASN1_TIME_adj()\fR instead and pass the offset value
  304. in the \fIoffset_sec\fR and \fIoffset_day\fR parameters instead of directly
  305. manipulating a time_t value.
  306. .PP
  307. \&\fBASN1_TIME_adj()\fR may change the type from \fB\s-1ASN1_GENERALIZEDTIME\s0\fR to
  308. \&\fB\s-1ASN1_UTCTIME\s0\fR, or vice versa, based on the resulting year.
  309. \&\fBASN1_GENERALIZEDTIME_adj()\fR and \fBASN1_UTCTIME_adj()\fR will not modify the type
  310. of the return structure.
  311. .PP
  312. It is recommended that functions starting with \fB\s-1ASN1_TIME\s0\fR be used instead of
  313. those starting with \fB\s-1ASN1_UTCTIME\s0\fR or \fB\s-1ASN1_GENERALIZEDTIME\s0\fR. The functions
  314. starting with \fB\s-1ASN1_UTCTIME\s0\fR and \fB\s-1ASN1_GENERALIZEDTIME\s0\fR act only on that
  315. specific time format. The functions starting with \fB\s-1ASN1_TIME\s0\fR will operate on
  316. either format.
  317. .SH "BUGS"
  318. .IX Header "BUGS"
  319. \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR do
  320. not print out the timezone: it either prints out \*(L"\s-1GMT\*(R"\s0 or nothing. But all
  321. certificates complying with \s-1RFC5280\s0 et al use \s-1GMT\s0 anyway.
  322. .PP
  323. \&\fBASN1_TIME_print()\fR, \fBASN1_TIME_print_ex()\fR, \fBASN1_UTCTIME_print()\fR and
  324. \&\fBASN1_GENERALIZEDTIME_print()\fR do not distinguish if they fail because
  325. of an I/O error or invalid time format.
  326. .PP
  327. Use the \fBASN1_TIME_normalize()\fR function to normalize the time value before
  328. printing to get \s-1GMT\s0 results.
  329. .SH "RETURN VALUES"
  330. .IX Header "RETURN VALUES"
  331. \&\fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR, \fBASN1_GENERALIZEDTIME_set()\fR,
  332. \&\fBASN1_TIME_adj()\fR, \fBASN1_UTCTIME_adj()\fR and \fBASN1_GENERALIZEDTIME_set()\fR return
  333. a pointer to a time structure or \s-1NULL\s0 if an error occurred.
  334. .PP
  335. \&\fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR,
  336. \&\fBASN1_GENERALIZEDTIME_set_string()\fR and \fBASN1_TIME_set_string_X509()\fR return
  337. 1 if the time value is successfully set and 0 otherwise.
  338. .PP
  339. \&\fBASN1_TIME_normalize()\fR returns 1 on success, and 0 on error.
  340. .PP
  341. \&\fBASN1_TIME_check()\fR, ASN1_UTCTIME_check and \fBASN1_GENERALIZEDTIME_check()\fR return 1
  342. if the structure is syntactically correct and 0 otherwise.
  343. .PP
  344. \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
  345. return 1 if the time is successfully printed out and
  346. 0 if an I/O error occurred an error occurred (I/O error or invalid time format).
  347. .PP
  348. \&\fBASN1_TIME_to_tm()\fR returns 1 if the time is successfully parsed and 0 if an
  349. error occurred (invalid time format).
  350. .PP
  351. \&\fBASN1_TIME_diff()\fR returns 1 for success and 0 for failure. It can fail if the
  352. passed-in time structure has invalid syntax, for example.
  353. .PP
  354. \&\fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR return \-1 if \fIs\fR is
  355. before \fIt\fR, 0 if \fIs\fR equals \fIt\fR, or 1 if \fIs\fR is after \fIt\fR. \-2 is returned
  356. on error.
  357. .PP
  358. \&\fBASN1_TIME_compare()\fR returns \-1 if \fIa\fR is before \fIb\fR, 0 if \fIa\fR equals \fIb\fR,
  359. or 1 if \fIa\fR is after \fIb\fR. \-2 is returned on error.
  360. .PP
  361. \&\fBASN1_TIME_to_generalizedtime()\fR returns a pointer to the appropriate time
  362. structure on success or \s-1NULL\s0 if an error occurred.
  363. .PP
  364. \&\fBASN1_TIME_dup()\fR, \fBASN1_UTCTIME_dup()\fR and \fBASN1_GENERALIZEDTIME_dup()\fR return a
  365. pointer to a time structure or \s-1NULL\s0 if an error occurred.
  366. .SH "EXAMPLES"
  367. .IX Header "EXAMPLES"
  368. Set a time structure to one hour after the current time and print it out:
  369. .PP
  370. .Vb 2
  371. \& #include <time.h>
  372. \& #include <openssl/asn1.h>
  373. \&
  374. \& ASN1_TIME *tm;
  375. \& time_t t;
  376. \& BIO *b;
  377. \&
  378. \& t = time(NULL);
  379. \& tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
  380. \& b = BIO_new_fp(stdout, BIO_NOCLOSE);
  381. \& ASN1_TIME_print(b, tm);
  382. \& ASN1_STRING_free(tm);
  383. \& BIO_free(b);
  384. .Ve
  385. .PP
  386. Determine if one time is later or sooner than the current time:
  387. .PP
  388. .Vb 1
  389. \& int day, sec;
  390. \&
  391. \& if (!ASN1_TIME_diff(&day, &sec, NULL, to))
  392. \& /* Invalid time format */
  393. \&
  394. \& if (day > 0 || sec > 0)
  395. \& printf("Later\en");
  396. \& else if (day < 0 || sec < 0)
  397. \& printf("Sooner\en");
  398. \& else
  399. \& printf("Same\en");
  400. .Ve
  401. .SH "HISTORY"
  402. .IX Header "HISTORY"
  403. The \fBASN1_TIME_to_tm()\fR function was added in OpenSSL 1.1.1.
  404. The \fBASN1_TIME_set_string_X509()\fR function was added in OpenSSL 1.1.1.
  405. The \fBASN1_TIME_normalize()\fR function was added in OpenSSL 1.1.1.
  406. The \fBASN1_TIME_cmp_time_t()\fR function was added in OpenSSL 1.1.1.
  407. The \fBASN1_TIME_compare()\fR function was added in OpenSSL 1.1.1.
  408. .SH "COPYRIGHT"
  409. .IX Header "COPYRIGHT"
  410. Copyright 2015\-2021 The OpenSSL Project Authors. All Rights Reserved.
  411. .PP
  412. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  413. this file except in compliance with the License. You can obtain a copy
  414. in the file \s-1LICENSE\s0 in the source distribution or at
  415. <https://www.openssl.org/source/license.html>.