xref: /minix3/crypto/external/bsd/openssl/dist/crypto/asn1/a_utctm.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc /* crypto/asn1/a_utctm.c */
2ebfedea0SLionel Sambuc /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3ebfedea0SLionel Sambuc  * All rights reserved.
4ebfedea0SLionel Sambuc  *
5ebfedea0SLionel Sambuc  * This package is an SSL implementation written
6ebfedea0SLionel Sambuc  * by Eric Young (eay@cryptsoft.com).
7ebfedea0SLionel Sambuc  * The implementation was written so as to conform with Netscapes SSL.
8ebfedea0SLionel Sambuc  *
9ebfedea0SLionel Sambuc  * This library is free for commercial and non-commercial use as long as
10ebfedea0SLionel Sambuc  * the following conditions are aheared to.  The following conditions
11ebfedea0SLionel Sambuc  * apply to all code found in this distribution, be it the RC4, RSA,
12ebfedea0SLionel Sambuc  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13ebfedea0SLionel Sambuc  * included with this distribution is covered by the same copyright terms
14ebfedea0SLionel Sambuc  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15ebfedea0SLionel Sambuc  *
16ebfedea0SLionel Sambuc  * Copyright remains Eric Young's, and as such any Copyright notices in
17ebfedea0SLionel Sambuc  * the code are not to be removed.
18ebfedea0SLionel Sambuc  * If this package is used in a product, Eric Young should be given attribution
19ebfedea0SLionel Sambuc  * as the author of the parts of the library used.
20ebfedea0SLionel Sambuc  * This can be in the form of a textual message at program startup or
21ebfedea0SLionel Sambuc  * in documentation (online or textual) provided with the package.
22ebfedea0SLionel Sambuc  *
23ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
24ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
25ebfedea0SLionel Sambuc  * are met:
26ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the copyright
27ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
28ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
29ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
30ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
31ebfedea0SLionel Sambuc  * 3. All advertising materials mentioning features or use of this software
32ebfedea0SLionel Sambuc  *    must display the following acknowledgement:
33ebfedea0SLionel Sambuc  *    "This product includes cryptographic software written by
34ebfedea0SLionel Sambuc  *     Eric Young (eay@cryptsoft.com)"
35ebfedea0SLionel Sambuc  *    The word 'cryptographic' can be left out if the rouines from the library
36ebfedea0SLionel Sambuc  *    being used are not cryptographic related :-).
37ebfedea0SLionel Sambuc  * 4. If you include any Windows specific code (or a derivative thereof) from
38ebfedea0SLionel Sambuc  *    the apps directory (application code) you must include an acknowledgement:
39ebfedea0SLionel Sambuc  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40ebfedea0SLionel Sambuc  *
41ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51ebfedea0SLionel Sambuc  * SUCH DAMAGE.
52ebfedea0SLionel Sambuc  *
53ebfedea0SLionel Sambuc  * The licence and distribution terms for any publically available version or
54ebfedea0SLionel Sambuc  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55ebfedea0SLionel Sambuc  * copied and put under another distribution licence
56ebfedea0SLionel Sambuc  * [including the GNU Public Licence.]
57ebfedea0SLionel Sambuc  */
58ebfedea0SLionel Sambuc 
59ebfedea0SLionel Sambuc #include <stdio.h>
60ebfedea0SLionel Sambuc #include <time.h>
61ebfedea0SLionel Sambuc #include "cryptlib.h"
62ebfedea0SLionel Sambuc #include "o_time.h"
63ebfedea0SLionel Sambuc #include <openssl/asn1.h>
64ebfedea0SLionel Sambuc 
65ebfedea0SLionel Sambuc #if 0
66ebfedea0SLionel Sambuc int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
67ebfedea0SLionel Sambuc {
68ebfedea0SLionel Sambuc # ifndef CHARSET_EBCDIC
69ebfedea0SLionel Sambuc     return (i2d_ASN1_bytes((ASN1_STRING *)a, pp,
70ebfedea0SLionel Sambuc                            V_ASN1_UTCTIME, V_ASN1_UNIVERSAL));
71ebfedea0SLionel Sambuc # else
72ebfedea0SLionel Sambuc     /* KLUDGE! We convert to ascii before writing DER */
73ebfedea0SLionel Sambuc     int len;
74ebfedea0SLionel Sambuc     char tmp[24];
75ebfedea0SLionel Sambuc     ASN1_STRING x = *(ASN1_STRING *)a;
76ebfedea0SLionel Sambuc 
77ebfedea0SLionel Sambuc     len = x.length;
78ebfedea0SLionel Sambuc     ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
79ebfedea0SLionel Sambuc     x.data = tmp;
80ebfedea0SLionel Sambuc     return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME, V_ASN1_UNIVERSAL);
81ebfedea0SLionel Sambuc # endif
82ebfedea0SLionel Sambuc }
83ebfedea0SLionel Sambuc 
84ebfedea0SLionel Sambuc ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
85ebfedea0SLionel Sambuc                                long length)
86ebfedea0SLionel Sambuc {
87ebfedea0SLionel Sambuc     ASN1_UTCTIME *ret = NULL;
88ebfedea0SLionel Sambuc 
89ebfedea0SLionel Sambuc     ret = (ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
90ebfedea0SLionel Sambuc                                          V_ASN1_UTCTIME, V_ASN1_UNIVERSAL);
91*0a6a1f1dSLionel Sambuc     if (ret == NULL) {
92ebfedea0SLionel Sambuc         ASN1err(ASN1_F_D2I_ASN1_UTCTIME, ERR_R_NESTED_ASN1_ERROR);
93ebfedea0SLionel Sambuc         return (NULL);
94ebfedea0SLionel Sambuc     }
95ebfedea0SLionel Sambuc # ifdef CHARSET_EBCDIC
96ebfedea0SLionel Sambuc     ascii2ebcdic(ret->data, ret->data, ret->length);
97ebfedea0SLionel Sambuc # endif
98*0a6a1f1dSLionel Sambuc     if (!ASN1_UTCTIME_check(ret)) {
99ebfedea0SLionel Sambuc         ASN1err(ASN1_F_D2I_ASN1_UTCTIME, ASN1_R_INVALID_TIME_FORMAT);
100ebfedea0SLionel Sambuc         goto err;
101ebfedea0SLionel Sambuc     }
102ebfedea0SLionel Sambuc 
103ebfedea0SLionel Sambuc     return (ret);
104ebfedea0SLionel Sambuc  err:
105ebfedea0SLionel Sambuc     if ((ret != NULL) && ((a == NULL) || (*a != ret)))
106ebfedea0SLionel Sambuc         M_ASN1_UTCTIME_free(ret);
107ebfedea0SLionel Sambuc     return (NULL);
108ebfedea0SLionel Sambuc }
109ebfedea0SLionel Sambuc 
110ebfedea0SLionel Sambuc #endif
111ebfedea0SLionel Sambuc 
ASN1_UTCTIME_check(ASN1_UTCTIME * d)112ebfedea0SLionel Sambuc int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
113ebfedea0SLionel Sambuc {
114ebfedea0SLionel Sambuc     static const int min[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };
115ebfedea0SLionel Sambuc     static const int max[8] = { 99, 12, 31, 23, 59, 59, 12, 59 };
116ebfedea0SLionel Sambuc     char *a;
117ebfedea0SLionel Sambuc     int n, i, l, o;
118ebfedea0SLionel Sambuc 
119*0a6a1f1dSLionel Sambuc     if (d->type != V_ASN1_UTCTIME)
120*0a6a1f1dSLionel Sambuc         return (0);
121ebfedea0SLionel Sambuc     l = d->length;
122ebfedea0SLionel Sambuc     a = (char *)d->data;
123ebfedea0SLionel Sambuc     o = 0;
124ebfedea0SLionel Sambuc 
125*0a6a1f1dSLionel Sambuc     if (l < 11)
126*0a6a1f1dSLionel Sambuc         goto err;
127*0a6a1f1dSLionel Sambuc     for (i = 0; i < 6; i++) {
128*0a6a1f1dSLionel Sambuc         if ((i == 5) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
129*0a6a1f1dSLionel Sambuc             i++;
130*0a6a1f1dSLionel Sambuc             break;
131*0a6a1f1dSLionel Sambuc         }
132*0a6a1f1dSLionel Sambuc         if ((a[o] < '0') || (a[o] > '9'))
133*0a6a1f1dSLionel Sambuc             goto err;
134ebfedea0SLionel Sambuc         n = a[o] - '0';
135*0a6a1f1dSLionel Sambuc         if (++o > l)
136*0a6a1f1dSLionel Sambuc             goto err;
137ebfedea0SLionel Sambuc 
138*0a6a1f1dSLionel Sambuc         if ((a[o] < '0') || (a[o] > '9'))
139*0a6a1f1dSLionel Sambuc             goto err;
140ebfedea0SLionel Sambuc         n = (n * 10) + a[o] - '0';
141*0a6a1f1dSLionel Sambuc         if (++o > l)
142*0a6a1f1dSLionel Sambuc             goto err;
143ebfedea0SLionel Sambuc 
144*0a6a1f1dSLionel Sambuc         if ((n < min[i]) || (n > max[i]))
145*0a6a1f1dSLionel Sambuc             goto err;
146ebfedea0SLionel Sambuc     }
147ebfedea0SLionel Sambuc     if (a[o] == 'Z')
148ebfedea0SLionel Sambuc         o++;
149*0a6a1f1dSLionel Sambuc     else if ((a[o] == '+') || (a[o] == '-')) {
150ebfedea0SLionel Sambuc         o++;
151*0a6a1f1dSLionel Sambuc         if (o + 4 > l)
152*0a6a1f1dSLionel Sambuc             goto err;
153*0a6a1f1dSLionel Sambuc         for (i = 6; i < 8; i++) {
154*0a6a1f1dSLionel Sambuc             if ((a[o] < '0') || (a[o] > '9'))
155*0a6a1f1dSLionel Sambuc                 goto err;
156ebfedea0SLionel Sambuc             n = a[o] - '0';
157ebfedea0SLionel Sambuc             o++;
158*0a6a1f1dSLionel Sambuc             if ((a[o] < '0') || (a[o] > '9'))
159*0a6a1f1dSLionel Sambuc                 goto err;
160ebfedea0SLionel Sambuc             n = (n * 10) + a[o] - '0';
161*0a6a1f1dSLionel Sambuc             if ((n < min[i]) || (n > max[i]))
162*0a6a1f1dSLionel Sambuc                 goto err;
163ebfedea0SLionel Sambuc             o++;
164ebfedea0SLionel Sambuc         }
165ebfedea0SLionel Sambuc     }
166ebfedea0SLionel Sambuc     return (o == l);
167ebfedea0SLionel Sambuc  err:
168ebfedea0SLionel Sambuc     return (0);
169ebfedea0SLionel Sambuc }
170ebfedea0SLionel Sambuc 
ASN1_UTCTIME_set_string(ASN1_UTCTIME * s,const char * str)171ebfedea0SLionel Sambuc int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
172ebfedea0SLionel Sambuc {
173ebfedea0SLionel Sambuc     ASN1_UTCTIME t;
174ebfedea0SLionel Sambuc 
175ebfedea0SLionel Sambuc     t.type = V_ASN1_UTCTIME;
176ebfedea0SLionel Sambuc     t.length = strlen(str);
177ebfedea0SLionel Sambuc     t.data = (unsigned char *)str;
178*0a6a1f1dSLionel Sambuc     if (ASN1_UTCTIME_check(&t)) {
179*0a6a1f1dSLionel Sambuc         if (s != NULL) {
180ebfedea0SLionel Sambuc             if (!ASN1_STRING_set((ASN1_STRING *)s,
181ebfedea0SLionel Sambuc                                  (unsigned char *)str, t.length))
182ebfedea0SLionel Sambuc                 return 0;
183ebfedea0SLionel Sambuc             s->type = V_ASN1_UTCTIME;
184ebfedea0SLionel Sambuc         }
185ebfedea0SLionel Sambuc         return (1);
186*0a6a1f1dSLionel Sambuc     } else
187ebfedea0SLionel Sambuc         return (0);
188ebfedea0SLionel Sambuc }
189ebfedea0SLionel Sambuc 
ASN1_UTCTIME_set(ASN1_UTCTIME * s,time_t t)190ebfedea0SLionel Sambuc ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
191ebfedea0SLionel Sambuc {
192ebfedea0SLionel Sambuc     return ASN1_UTCTIME_adj(s, t, 0, 0);
193ebfedea0SLionel Sambuc }
194ebfedea0SLionel Sambuc 
ASN1_UTCTIME_adj(ASN1_UTCTIME * s,time_t t,int offset_day,long offset_sec)195ebfedea0SLionel Sambuc ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
196ebfedea0SLionel Sambuc                                int offset_day, long offset_sec)
197ebfedea0SLionel Sambuc {
198ebfedea0SLionel Sambuc     char *p;
199ebfedea0SLionel Sambuc     struct tm *ts;
200ebfedea0SLionel Sambuc     struct tm data;
201ebfedea0SLionel Sambuc     size_t len = 20;
202*0a6a1f1dSLionel Sambuc     int free_s = 0;
203ebfedea0SLionel Sambuc 
204*0a6a1f1dSLionel Sambuc     if (s == NULL) {
205*0a6a1f1dSLionel Sambuc         free_s = 1;
206ebfedea0SLionel Sambuc         s = M_ASN1_UTCTIME_new();
207*0a6a1f1dSLionel Sambuc     }
208ebfedea0SLionel Sambuc     if (s == NULL)
209*0a6a1f1dSLionel Sambuc         goto err;
210ebfedea0SLionel Sambuc 
211ebfedea0SLionel Sambuc     ts = OPENSSL_gmtime(&t, &data);
212ebfedea0SLionel Sambuc     if (ts == NULL)
213*0a6a1f1dSLionel Sambuc         goto err;
214ebfedea0SLionel Sambuc 
215*0a6a1f1dSLionel Sambuc     if (offset_day || offset_sec) {
216ebfedea0SLionel Sambuc         if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
217*0a6a1f1dSLionel Sambuc             goto err;
218ebfedea0SLionel Sambuc     }
219ebfedea0SLionel Sambuc 
220ebfedea0SLionel Sambuc     if ((ts->tm_year < 50) || (ts->tm_year >= 150))
221*0a6a1f1dSLionel Sambuc         goto err;
222ebfedea0SLionel Sambuc 
223ebfedea0SLionel Sambuc     p = (char *)s->data;
224*0a6a1f1dSLionel Sambuc     if ((p == NULL) || ((size_t)s->length < len)) {
225ebfedea0SLionel Sambuc         p = OPENSSL_malloc(len);
226*0a6a1f1dSLionel Sambuc         if (p == NULL) {
227ebfedea0SLionel Sambuc             ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
228*0a6a1f1dSLionel Sambuc             goto err;
229ebfedea0SLionel Sambuc         }
230ebfedea0SLionel Sambuc         if (s->data != NULL)
231ebfedea0SLionel Sambuc             OPENSSL_free(s->data);
232ebfedea0SLionel Sambuc         s->data = (unsigned char *)p;
233ebfedea0SLionel Sambuc     }
234ebfedea0SLionel Sambuc 
235ebfedea0SLionel Sambuc     BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100,
236*0a6a1f1dSLionel Sambuc                  ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min,
237*0a6a1f1dSLionel Sambuc                  ts->tm_sec);
238ebfedea0SLionel Sambuc     s->length = strlen(p);
239ebfedea0SLionel Sambuc     s->type = V_ASN1_UTCTIME;
240ebfedea0SLionel Sambuc #ifdef CHARSET_EBCDIC_not
241ebfedea0SLionel Sambuc     ebcdic2ascii(s->data, s->data, s->length);
242ebfedea0SLionel Sambuc #endif
243ebfedea0SLionel Sambuc     return (s);
244*0a6a1f1dSLionel Sambuc  err:
245*0a6a1f1dSLionel Sambuc     if (free_s && s)
246*0a6a1f1dSLionel Sambuc         M_ASN1_UTCTIME_free(s);
247*0a6a1f1dSLionel Sambuc     return NULL;
248ebfedea0SLionel Sambuc }
249ebfedea0SLionel Sambuc 
ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME * s,time_t t)250ebfedea0SLionel Sambuc int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
251ebfedea0SLionel Sambuc {
252ebfedea0SLionel Sambuc     struct tm *tm;
253ebfedea0SLionel Sambuc     struct tm data;
254ebfedea0SLionel Sambuc     int offset;
255ebfedea0SLionel Sambuc     int year;
256ebfedea0SLionel Sambuc 
257ebfedea0SLionel Sambuc #define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
258ebfedea0SLionel Sambuc 
259ebfedea0SLionel Sambuc     if (s->data[12] == 'Z')
260ebfedea0SLionel Sambuc         offset = 0;
261*0a6a1f1dSLionel Sambuc     else {
262ebfedea0SLionel Sambuc         offset = g2(s->data + 13) * 60 + g2(s->data + 15);
263ebfedea0SLionel Sambuc         if (s->data[12] == '-')
264ebfedea0SLionel Sambuc             offset = -offset;
265ebfedea0SLionel Sambuc     }
266ebfedea0SLionel Sambuc 
267ebfedea0SLionel Sambuc     t -= offset * 60;           /* FIXME: may overflow in extreme cases */
268ebfedea0SLionel Sambuc 
269ebfedea0SLionel Sambuc     tm = OPENSSL_gmtime(&t, &data);
270*0a6a1f1dSLionel Sambuc     /*
271*0a6a1f1dSLionel Sambuc      * NB: -1, 0, 1 already valid return values so use -2 to indicate error.
272*0a6a1f1dSLionel Sambuc      */
273*0a6a1f1dSLionel Sambuc     if (tm == NULL)
274*0a6a1f1dSLionel Sambuc         return -2;
275ebfedea0SLionel Sambuc 
276ebfedea0SLionel Sambuc #define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1
277ebfedea0SLionel Sambuc     year = g2(s->data);
278ebfedea0SLionel Sambuc     if (year < 50)
279ebfedea0SLionel Sambuc         year += 100;
280ebfedea0SLionel Sambuc     return_cmp(year, tm->tm_year);
281ebfedea0SLionel Sambuc     return_cmp(g2(s->data + 2) - 1, tm->tm_mon);
282ebfedea0SLionel Sambuc     return_cmp(g2(s->data + 4), tm->tm_mday);
283ebfedea0SLionel Sambuc     return_cmp(g2(s->data + 6), tm->tm_hour);
284ebfedea0SLionel Sambuc     return_cmp(g2(s->data + 8), tm->tm_min);
285ebfedea0SLionel Sambuc     return_cmp(g2(s->data + 10), tm->tm_sec);
286ebfedea0SLionel Sambuc #undef g2
287ebfedea0SLionel Sambuc #undef return_cmp
288ebfedea0SLionel Sambuc 
289ebfedea0SLionel Sambuc     return 0;
290ebfedea0SLionel Sambuc }
291ebfedea0SLionel Sambuc 
292ebfedea0SLionel Sambuc #if 0
293ebfedea0SLionel Sambuc time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
294ebfedea0SLionel Sambuc {
295ebfedea0SLionel Sambuc     struct tm tm;
296ebfedea0SLionel Sambuc     int offset;
297ebfedea0SLionel Sambuc 
298ebfedea0SLionel Sambuc     memset(&tm, '\0', sizeof tm);
299ebfedea0SLionel Sambuc 
300ebfedea0SLionel Sambuc # define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
301ebfedea0SLionel Sambuc     tm.tm_year = g2(s->data);
302ebfedea0SLionel Sambuc     if (tm.tm_year < 50)
303ebfedea0SLionel Sambuc         tm.tm_year += 100;
304ebfedea0SLionel Sambuc     tm.tm_mon = g2(s->data + 2) - 1;
305ebfedea0SLionel Sambuc     tm.tm_mday = g2(s->data + 4);
306ebfedea0SLionel Sambuc     tm.tm_hour = g2(s->data + 6);
307ebfedea0SLionel Sambuc     tm.tm_min = g2(s->data + 8);
308ebfedea0SLionel Sambuc     tm.tm_sec = g2(s->data + 10);
309ebfedea0SLionel Sambuc     if (s->data[12] == 'Z')
310ebfedea0SLionel Sambuc         offset = 0;
311*0a6a1f1dSLionel Sambuc     else {
312ebfedea0SLionel Sambuc         offset = g2(s->data + 13) * 60 + g2(s->data + 15);
313ebfedea0SLionel Sambuc         if (s->data[12] == '-')
314ebfedea0SLionel Sambuc             offset = -offset;
315ebfedea0SLionel Sambuc     }
316ebfedea0SLionel Sambuc # undef g2
317ebfedea0SLionel Sambuc 
318*0a6a1f1dSLionel Sambuc     /*
319*0a6a1f1dSLionel Sambuc      * FIXME: mktime assumes the current timezone
320ebfedea0SLionel Sambuc      * instead of UTC, and unless we rewrite OpenSSL
321ebfedea0SLionel Sambuc      * in Lisp we cannot locally change the timezone
322ebfedea0SLionel Sambuc      * without possibly interfering with other parts
323ebfedea0SLionel Sambuc      * of the program. timegm, which uses UTC, is
324ebfedea0SLionel Sambuc      * non-standard.
325ebfedea0SLionel Sambuc      * Also time_t is inappropriate for general
326*0a6a1f1dSLionel Sambuc      * UTC times because it may a 32 bit type.
327*0a6a1f1dSLionel Sambuc      */
328*0a6a1f1dSLionel Sambuc     return mktime(&tm) - offset * 60;
329ebfedea0SLionel Sambuc }
330ebfedea0SLionel Sambuc #endif
331