As ftruncate is not availabe on all platforms, switch back to
[oweals/openssl.git] / crypto / asn1 / a_time.c
index 848688b7dbd6aa6df969bbd7e12beaf89fa6a5a2..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));
@@ -98,11 +119,11 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
 
 #if defined(THREADS) && !defined(WIN32)
        gmtime_r(&t,&data);
-    ts=&data;
+       ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
 #else
        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);
        }