Replace the macros in asn1.h with function equivalents. Also make UTF8Strings
[openssl.git] / crypto / asn1 / a_time.c
index 953ed6088d19b2ea8970701c45d51c1ee601e030..d1900f68e459b57d4fe047958ec1e20e84f947c9 100644 (file)
 #include <stdio.h>
 #include <time.h>
 #include "cryptlib.h"
-#include "asn1.h"
+#include <openssl/asn1.h>
 
-int i2d_ASN1_TIME(a,pp)
-ASN1_TIME *a;
-unsigned char **pp;
+ASN1_TIME *ASN1_TIME_new(void)
+{ return M_ASN1_TIME_new(); }
+
+void ASN1_TIME_free(ASN1_TIME *x)
+{ return 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));
@@ -78,10 +97,7 @@ unsigned char **pp;
        }
 
 
-ASN1_TIME *d2i_ASN1_TIME(a, pp, length)
-ASN1_TIME **a;
-unsigned char **pp;
-long length;
+ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
        {
        unsigned char tag;
        tag = **pp & ~V_ASN1_CONSTRUCTED;
@@ -94,9 +110,7 @@ long length;
        }
 
 
-ASN1_TIME *ASN1_TIME_set(s, t)
-ASN1_TIME *s;
-time_t t;
+ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
        {
        struct tm *ts;
 #if defined(THREADS) && !defined(WIN32)
@@ -104,11 +118,12 @@ 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);
        }