diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_utctm.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_utctm.c | 90 |
1 files changed, 86 insertions, 4 deletions
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c index 07565974e3..d381c9e0d1 100644 --- a/src/lib/libcrypto/asn1/a_utctm.c +++ b/src/lib/libcrypto/asn1/a_utctm.c | |||
| @@ -193,7 +193,8 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | |||
| 193 | { | 193 | { |
| 194 | char *p; | 194 | char *p; |
| 195 | struct tm *ts; | 195 | struct tm *ts; |
| 196 | #if defined(THREADS) && !defined(WIN32) | 196 | #if defined(THREADS) && !defined(WIN32) && !defined(__CYGWIN32__) |
| 197 | |||
| 197 | struct tm data; | 198 | struct tm data; |
| 198 | #endif | 199 | #endif |
| 199 | 200 | ||
| @@ -202,7 +203,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | |||
| 202 | if (s == NULL) | 203 | if (s == NULL) |
| 203 | return(NULL); | 204 | return(NULL); |
| 204 | 205 | ||
| 205 | #if defined(THREADS) && !defined(WIN32) | 206 | #if defined(THREADS) && !defined(WIN32) && !defined(__CYGWIN32__) |
| 206 | gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ | 207 | gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ |
| 207 | ts=&data; | 208 | ts=&data; |
| 208 | #else | 209 | #else |
| @@ -248,10 +249,10 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | |||
| 248 | p=(char *)s->data; | 249 | p=(char *)s->data; |
| 249 | if ((p == NULL) || (s->length < 14)) | 250 | if ((p == NULL) || (s->length < 14)) |
| 250 | { | 251 | { |
| 251 | p=Malloc(20); | 252 | p=OPENSSL_malloc(20); |
| 252 | if (p == NULL) return(NULL); | 253 | if (p == NULL) return(NULL); |
| 253 | if (s->data != NULL) | 254 | if (s->data != NULL) |
| 254 | Free(s->data); | 255 | OPENSSL_free(s->data); |
| 255 | s->data=(unsigned char *)p; | 256 | s->data=(unsigned char *)p; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| @@ -264,3 +265,84 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | |||
| 264 | #endif | 265 | #endif |
| 265 | return(s); | 266 | return(s); |
| 266 | } | 267 | } |
| 268 | |||
| 269 | |||
| 270 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | ||
| 271 | { | ||
| 272 | struct tm *tm; | ||
| 273 | int offset; | ||
| 274 | int year; | ||
| 275 | |||
| 276 | #define g2(p) (((p)[0]-'0')*10+(p)[1]-'0') | ||
| 277 | |||
| 278 | if (s->data[12] == 'Z') | ||
| 279 | offset=0; | ||
| 280 | else | ||
| 281 | { | ||
| 282 | offset = g2(s->data+13)*60+g2(s->data+15); | ||
| 283 | if (s->data[12] == '-') | ||
| 284 | offset = -offset; | ||
| 285 | } | ||
| 286 | |||
| 287 | t -= offset*60; /* FIXME: may overflow in extreme cases */ | ||
| 288 | |||
| 289 | #if defined(THREADS) && !defined(WIN32) && !defined(__CYGWIN32__) | ||
| 290 | { struct tm data; gmtime_r(&t, &data); tm = &data; } | ||
| 291 | #else | ||
| 292 | tm = gmtime(&t); | ||
| 293 | #endif | ||
| 294 | |||
| 295 | #define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1 | ||
| 296 | year = g2(s->data); | ||
| 297 | if (year < 50) | ||
| 298 | year += 100; | ||
| 299 | return_cmp(year, tm->tm_year); | ||
| 300 | return_cmp(g2(s->data+2) - 1, tm->tm_mon); | ||
| 301 | return_cmp(g2(s->data+4), tm->tm_mday); | ||
| 302 | return_cmp(g2(s->data+6), tm->tm_hour); | ||
| 303 | return_cmp(g2(s->data+8), tm->tm_min); | ||
| 304 | return_cmp(g2(s->data+10), tm->tm_sec); | ||
| 305 | #undef g2 | ||
| 306 | #undef return_cmp | ||
| 307 | |||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | #if 0 | ||
| 313 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | ||
| 314 | { | ||
| 315 | struct tm tm; | ||
| 316 | int offset; | ||
| 317 | |||
| 318 | memset(&tm,'\0',sizeof tm); | ||
| 319 | |||
| 320 | #define g2(p) (((p)[0]-'0')*10+(p)[1]-'0') | ||
| 321 | tm.tm_year=g2(s->data); | ||
| 322 | if(tm.tm_year < 50) | ||
| 323 | tm.tm_year+=100; | ||
| 324 | tm.tm_mon=g2(s->data+2)-1; | ||
| 325 | tm.tm_mday=g2(s->data+4); | ||
| 326 | tm.tm_hour=g2(s->data+6); | ||
| 327 | tm.tm_min=g2(s->data+8); | ||
| 328 | tm.tm_sec=g2(s->data+10); | ||
| 329 | if(s->data[12] == 'Z') | ||
| 330 | offset=0; | ||
| 331 | else | ||
| 332 | { | ||
| 333 | offset=g2(s->data+13)*60+g2(s->data+15); | ||
| 334 | if(s->data[12] == '-') | ||
| 335 | offset= -offset; | ||
| 336 | } | ||
| 337 | #undef g2 | ||
| 338 | |||
| 339 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone | ||
| 340 | * instead of UTC, and unless we rewrite OpenSSL | ||
| 341 | * in Lisp we cannot locally change the timezone | ||
| 342 | * without possibly interfering with other parts | ||
| 343 | * of the program. timegm, which uses UTC, is | ||
| 344 | * non-standard. | ||
| 345 | * Also time_t is inappropriate for general | ||
| 346 | * UTC times because it may a 32 bit type. */ | ||
| 347 | } | ||
| 348 | #endif | ||
