Increase print buffer (10K instead of just 2K).
[oweals/openssl.git] / crypto / asn1 / a_utctm.c
index ba349455a175856d4e441d36e416820da298c925..2ee572e2281aad2e7c9cad76379e7608ebc680f8 100644 (file)
@@ -70,7 +70,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_new(void)
 { return M_ASN1_UTCTIME_new(); }
 
 void ASN1_UTCTIME_free(ASN1_UTCTIME *x)
-{ return M_ASN1_UTCTIME_free(x); }
+{ M_ASN1_UTCTIME_free(x); }
 
 int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
        {
@@ -248,10 +248,10 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
        p=(char *)s->data;
        if ((p == NULL) || (s->length < 14))
                {
-               p=Malloc(20);
+               p=OPENSSL_malloc(20);
                if (p == NULL) return(NULL);
                if (s->data != NULL)
-                       Free(s->data);
+                       OPENSSL_free(s->data);
                s->data=(unsigned char *)p;
                }
 
@@ -264,3 +264,39 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
 #endif
        return(s);
        }
+
+time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
+       {
+       struct tm tm;
+       int offset;
+
+       memset(&tm,'\0',sizeof tm);
+
+#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
+       tm.tm_year=g2(s->data);
+       if(tm.tm_year < 50)
+               tm.tm_year+=100;
+       tm.tm_mon=g2(s->data+2)-1;
+       tm.tm_mday=g2(s->data+4);
+       tm.tm_hour=g2(s->data+6);
+       tm.tm_min=g2(s->data+8);
+       tm.tm_sec=g2(s->data+10);
+       if(s->data[12] == 'Z')
+               offset=0;
+       else
+               {
+               offset=g2(s->data+13)*60+g2(s->data+15);
+               if(s->data[12] == '-')
+                       offset= -offset;
+               }
+#undef g2
+
+       return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone
+                                      * instead of UTC, and unless we rewrite OpenSSL
+                                      * in Lisp we cannot locally change the timezone
+                                      * without possibly interfering with other parts
+                                      * of the program. timegm, which uses UTC, is
+                                      * non-standard.
+                                      * Also time_t is inappropriate for general
+                                      * UTC times because it may a 32 bit type. */
+       }