Created
March 20, 2014 12:29
-
-
Save kyprizel/9662696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static time_t | |
| ASN1_GetTimeT(ASN1_TIME* time) | |
| { | |
| struct tm t; | |
| const char* str = (const char*) time->data; | |
| memset(&t, 0, sizeof(t)); | |
| if (time->length < 14) { | |
| goto complete; | |
| } | |
| if (time->type == V_ASN1_UTCTIME) { /* two digit year */ | |
| t.tm_year = (str[0] - '0') * 10 + (str[1] - '0'); | |
| if (t.tm_year < 70) | |
| t.tm_year += 100; | |
| } else if (time->type == V_ASN1_GENERALIZEDTIME) { /* four digit year */ | |
| t.tm_year = (str[0] - '0') * 1000 + (str[1] - '0') * 100 + (str[2] - '0') * 10 + (str[3] - '0'); | |
| t.tm_year -= 1900; | |
| } | |
| t.tm_mon = ((str[4] - '0') * 10 + (str[5] - '0')) - 1; // -1 since January is 0 not 1. | |
| t.tm_mday = (str[6] - '0') * 10 + (str[7] - '0'); | |
| t.tm_hour = (str[8] - '0') * 10 + (str[9] - '0'); | |
| t.tm_min = (str[10] - '0') * 10 + (str[11] - '0'); | |
| t.tm_sec = (str[12] - '0') * 10 + (str[13] - '0'); | |
| complete: | |
| return mktime(&t); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment