X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fasn1%2Fa_utctm.c;h=b855867dc1d30693bff1e8aa925f95884d64eccc;hb=4dbe060f2c911f1fbd617f9de7e7fde5964fae44;hp=688199fdd2292e5cffcf270e45c0154782b63cba;hpb=a53955d8abd68c604de02cc1e101c66169207fb7;p=oweals%2Fopenssl.git diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c index 688199fdd2..b855867dc1 100644 --- a/crypto/asn1/a_utctm.c +++ b/crypto/asn1/a_utctm.c @@ -66,6 +66,12 @@ #include "cryptlib.h" #include +ASN1_UTCTIME *ASN1_UTCTIME_new(void) +{ return M_ASN1_UTCTIME_new(); } + +void ASN1_UTCTIME_free(ASN1_UTCTIME *x) +{ M_ASN1_UTCTIME_free(x); } + int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) { #ifndef CHARSET_EBCDIC @@ -109,7 +115,7 @@ ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, return(ret); err: if ((ret != NULL) && ((a == NULL) || (*a != ret))) - ASN1_UTCTIME_free(ret); + M_ASN1_UTCTIME_free(ret); return(NULL); } @@ -192,7 +198,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) #endif if (s == NULL) - s=ASN1_UTCTIME_new(); + s=M_ASN1_UTCTIME_new(); if (s == NULL) return(NULL); @@ -258,3 +264,32 @@ 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; + }