]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/ASN1_TIME_set.3
Merge OpenSSL 1.0.2r.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / ASN1_TIME_set.3
1 .\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35)
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 3"
136 .TH ASN1_TIME_set 3 "2019-02-26" "1.0.2r" "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_TIME_adj, ASN1_TIME_check, ASN1_TIME_set_string,
143 ASN1_TIME_print, ASN1_TIME_diff \- ASN.1 Time functions.
144 .SH "SYNOPSIS"
145 .IX Header "SYNOPSIS"
146 .Vb 6
147 \& ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
148 \& ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
149 \&                          int offset_day, long offset_sec);
150 \& int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
151 \& int ASN1_TIME_check(const ASN1_TIME *t);
152 \& int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
153 \&
154 \& int ASN1_TIME_diff(int *pday, int *psec,
155 \&                    const ASN1_TIME *from, const ASN1_TIME *to);
156 .Ve
157 .SH "DESCRIPTION"
158 .IX Header "DESCRIPTION"
159 The function \fBASN1_TIME_set()\fR sets the \s-1ASN1_TIME\s0 structure \fBs\fR to the
160 time represented by the time_t value \fBt\fR. If \fBs\fR is \s-1NULL\s0 a new \s-1ASN1_TIME\s0
161 structure is allocated and returned.
162 .PP
163 \&\fBASN1_TIME_adj()\fR sets the \s-1ASN1_TIME\s0 structure \fBs\fR to the time represented
164 by the time \fBoffset_day\fR and \fBoffset_sec\fR after the time_t value \fBt\fR.
165 The values of \fBoffset_day\fR or \fBoffset_sec\fR can be negative to set a
166 time before \fBt\fR. The \fBoffset_sec\fR value can also exceed the number of
167 seconds in a day. If \fBs\fR is \s-1NULL\s0 a new \s-1ASN1_TIME\s0 structure is allocated
168 and returned.
169 .PP
170 \&\fBASN1_TIME_set_string()\fR sets \s-1ASN1_TIME\s0 structure \fBs\fR to the time
171 represented by string \fBstr\fR which must be in appropriate \s-1ASN.1\s0 time
172 format (for example \s-1YYMMDDHHMMSSZ\s0 or \s-1YYYYMMDDHHMMSSZ\s0).
173 .PP
174 \&\fBASN1_TIME_check()\fR checks the syntax of \s-1ASN1_TIME\s0 structure \fBs\fR.
175 .PP
176 \&\fBASN1_TIME_print()\fR prints out the time \fBs\fR to \s-1BIO\s0 \fBb\fR in human readable
177 format. It will be of the format \s-1MMM DD HH:MM:SS YYYY\s0 [\s-1GMT\s0], for example
178 \&\*(L"Feb  3 00:55:52 2015 \s-1GMT\*(R"\s0 it does not include a newline. If the time
179 structure has invalid format it prints out \*(L"Bad time value\*(R" and returns
180 an error.
181 .PP
182 \&\fBASN1_TIME_diff()\fR sets \fB*pday\fR and \fB*psec\fR to the time difference between
183 \&\fBfrom\fR and \fBto\fR. If \fBto\fR represents a time later than \fBfrom\fR then
184 one or both (depending on the time difference) of \fB*pday\fR and \fB*psec\fR
185 will be positive. If \fBto\fR represents a time earlier than \fBfrom\fR then
186 one or both of \fB*pday\fR and \fB*psec\fR will be negative. If \fBto\fR and \fBfrom\fR
187 represent the same time then \fB*pday\fR and \fB*psec\fR will both be zero.
188 If both \fB*pday\fR and \fB*psec\fR are non-zero they will always have the same
189 sign. The value of \fB*psec\fR will always be less than the number of seconds
190 in a day. If \fBfrom\fR or \fBto\fR is \s-1NULL\s0 the current time is used.
191 .SH "NOTES"
192 .IX Header "NOTES"
193 The \s-1ASN1_TIME\s0 structure corresponds to the \s-1ASN.1\s0 structure \fBTime\fR
194 defined in \s-1RFC5280\s0 et al. The time setting functions obey the rules outlined
195 in \s-1RFC5280:\s0 if the date can be represented by UTCTime it is used, else
196 GeneralizedTime is used.
197 .PP
198 The \s-1ASN1_TIME\s0 structure is represented as an \s-1ASN1_STRING\s0 internally and can
199 be freed up using \fBASN1_STRING_free()\fR.
200 .PP
201 The \s-1ASN1_TIME\s0 structure can represent years from 0000 to 9999 but no attempt
202 is made to correct ancient calendar changes (for example from Julian to
203 Gregorian calendars).
204 .PP
205 Some applications add offset times directly to a time_t value and pass the
206 results to \fBASN1_TIME_set()\fR (or equivalent). This can cause problems as the
207 time_t value can overflow on some systems resulting in unexpected results.
208 New applications should use \fBASN1_TIME_adj()\fR instead and pass the offset value
209 in the \fBoffset_sec\fR and \fBoffset_day\fR parameters instead of directly
210 manipulating a time_t value.
211 .SH "BUGS"
212 .IX Header "BUGS"
213 \&\fBASN1_TIME_print()\fR currently does not print out the time zone: it either prints
214 out \*(L"\s-1GMT\*(R"\s0 or nothing. But all certificates complying with \s-1RFC5280\s0 et al use \s-1GMT\s0
215 anyway.
216 .SH "EXAMPLES"
217 .IX Header "EXAMPLES"
218 Set a time structure to one hour after the current time and print it out:
219 .PP
220 .Vb 11
221 \& #include <time.h>
222 \& #include <openssl/asn1.h>
223 \& ASN1_TIME *tm;
224 \& time_t t;
225 \& BIO *b;
226 \& t = time(NULL);
227 \& tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
228 \& b = BIO_new_fp(stdout, BIO_NOCLOSE);
229 \& ASN1_TIME_print(b, tm);
230 \& ASN1_STRING_free(tm);
231 \& BIO_free(b);
232 .Ve
233 .PP
234 Determine if one time is later or sooner than the current time:
235 .PP
236 .Vb 1
237 \& int day, sec;
238 \&
239 \& if (!ASN1_TIME_diff(&day, &sec, NULL, to))
240 \&        /* Invalid time format */
241 \&
242 \& if (day > 0 || sec > 0)
243 \&   printf("Later\en");
244 \& else if (day < 0 || sec < 0)
245 \&   printf("Sooner\en");
246 \& else
247 \&   printf("Same\en");
248 .Ve
249 .SH "RETURN VALUES"
250 .IX Header "RETURN VALUES"
251 \&\fBASN1_TIME_set()\fR and \fBASN1_TIME_adj()\fR return a pointer to an \s-1ASN1_TIME\s0 structure
252 or \s-1NULL\s0 if an error occurred.
253 .PP
254 \&\fBASN1_TIME_set_string()\fR returns 1 if the time value is successfully set and
255 0 otherwise.
256 .PP
257 \&\fBASN1_TIME_check()\fR returns 1 if the structure is syntactically correct and 0
258 otherwise.
259 .PP
260 \&\fBASN1_TIME_print()\fR returns 1 if the time is successfully printed out and 0 if
261 an error occurred (I/O error or invalid time format).
262 .PP
263 \&\fBASN1_TIME_diff()\fR returns 1 for sucess and 0 for failure. It can fail if the
264 pass \s-1ASN1_TIME\s0 structure has invalid syntax for example.