experimental function to convert ASN1_TIME to tm, not used or even compiled in yet
[openssl.git] / crypto / asn1 / a_utctm.c
index 2d15ff3c14e0d78e82b794ff8395360398e17c77..75608df3369d1b85376cb45a4c7e13bdc1ad3c4d 100644 (file)
@@ -112,7 +112,7 @@ err:
 
 #endif
 
-int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
+int ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
        {
        static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
        static const int max[8]={99,12,31,23,59,59,12,59};
@@ -186,6 +186,12 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
 
 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
        {
+       return ASN1_UTCTIME_adj(s, t, 0, 0);
+       }
+
+ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
+                               int offset_day, long offset_sec)
+       {
        char *p;
        struct tm *ts;
        struct tm data;
@@ -200,13 +206,22 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
        if (ts == NULL)
                return(NULL);
 
+       if (offset_day || offset_sec)
+               { 
+               if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
+                       return NULL;
+               }
+
+       if((ts->tm_year < 50) || (ts->tm_year >= 150))
+               return NULL;
+
        p=(char *)s->data;
        if ((p == NULL) || ((size_t)s->length < len))
                {
                p=OPENSSL_malloc(len);
                if (p == NULL)
                        {
-                       ASN1err(ASN1_F_ASN1_UTCTIME_SET,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
                        return(NULL);
                        }
                if (s->data != NULL)