Skip to content

Commit 962325b

Browse files
committed
Refactor date parsing
1 parent c1f9398 commit 962325b

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

examples/ocsp_responder/ocsp_responder.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,13 @@ static IndexEntry* ParseIndexFile(const char* filename)
322322
if (field[0] != '\0') {
323323
struct tm tm;
324324
XMEMSET(&tm, 0, sizeof(tm));
325-
/* Format: YYMMDDHHMMSSZ */
326-
if (XSTRLEN(field) >= 12) {
327-
int year = (field[0] - '0') * 10 + (field[1] - '0');
328-
tm.tm_year = (year < 50) ? (100 + year) : year;
329-
tm.tm_mon = (field[2] - '0') * 10 + (field[3] - '0') - 1;
330-
tm.tm_mday = (field[4] - '0') * 10 + (field[5] - '0');
331-
tm.tm_hour = (field[6] - '0') * 10 + (field[7] - '0');
332-
tm.tm_min = (field[8] - '0') * 10 + (field[9] - '0');
333-
tm.tm_sec = (field[10] - '0') * 10 + (field[11] - '0');
334-
entry->revocationTime = XMKTIME(&tm);
325+
if (wc_GetDateAsCalendarTime((const byte*)field,
326+
(int)XSTRLEN(field), ASN_UTC_TIME, &tm) != 0) {
327+
LOG_ERROR("Invalid revocation time format: %s\n", field);
328+
entry->revocationTime = (time_t)-1;
329+
break;
335330
}
331+
entry->revocationTime = XMKTIME(&tm);
336332
}
337333
break;
338334
case 3: /* Serial (hex) */

0 commit comments

Comments
 (0)