Clarification.
[openssl.git] / crypto / asn1 / a_time.c
index 19bfdda7c432811f3cb14d83b963ff89b48e40f1..b193f1c71fb67637accd5eb591201f691845b8ab 100644 (file)
 #include "cryptlib.h"
 #include <openssl/asn1.h>
 
+ASN1_TIME *ASN1_TIME_new(void)
+{ return M_ASN1_TIME_new(); }
+
+void ASN1_TIME_free(ASN1_TIME *x)
+{ M_ASN1_TIME_free(x); }
+
 int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
        {
+#ifdef CHARSET_EBCDIC
+       /* KLUDGE! We convert to ascii before writing DER */
+       char tmp[24];
+       ASN1_STRING tmpstr;
+
+       if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
+           int len;
+
+           tmpstr = *(ASN1_STRING *)a;
+           len = tmpstr.length;
+           ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
+           tmpstr.data = tmp;
+           a = (ASN1_GENERALIZEDTIME *) &tmpstr;
+       }
+#endif
        if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
                                return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
                                     a->type ,V_ASN1_UNIVERSAL));
@@ -97,11 +118,12 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
 #endif
 
 #if defined(THREADS) && !defined(WIN32)
-       ts=(struct tm *)gmtime_r(&t,&data);
+       gmtime_r(&t,&data);
+       ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
 #else
-       ts=(struct tm *)gmtime(&t);
+       ts=gmtime(&t);
 #endif
-       if((ts->tm_year >= 1950) && (ts->tm_year < 2050))
+       if((ts->tm_year >= 50) && (ts->tm_year < 150))
                                        return ASN1_UTCTIME_set(s, t);
        return ASN1_GENERALIZEDTIME_set(s,t);
        }