#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)
+{ 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));
}
-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;
}
-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)
#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);
}