static int check_time(long offset) { struct tm tm1, tm2, o1; int off_day, off_sec; long toffset; time_t t1, t2; time(&t1); t2 = t1 + offset; OPENSSL_gmtime(&t2, &tm2); OPENSSL_gmtime(&t1, &tm1); o1 = tm1; OPENSSL_gmtime_adj(&tm1, 0, offset); if (!TEST_int_eq(tm1.tm_year, tm2.tm_year) || !TEST_int_eq(tm1.tm_mon, tm2.tm_mon) || !TEST_int_eq(tm1.tm_mday, tm2.tm_mday) || !TEST_int_eq(tm1.tm_hour, tm2.tm_hour) || !TEST_int_eq(tm1.tm_min, tm2.tm_min) || !TEST_int_eq(tm1.tm_sec, tm2.tm_sec) || !TEST_true(OPENSSL_gmtime_diff(&off_day, &off_sec, &o1, &tm1))) return 0; toffset = (long)off_day * SECS_PER_DAY + off_sec; if (!TEST_long_eq(offset, toffset)) return 0; return 1; }
int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to) { struct tm tm_from, tm_to; if (!asn1_time_to_tm(&tm_from, from)) return 0; if (!asn1_time_to_tm(&tm_to, to)) return 0; return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); }
int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t) { struct tm stm, ttm; int day, sec; if (!ASN1_TIME_to_tm(s, &stm)) return -2; if (!OPENSSL_gmtime(&t, &ttm)) return -2; if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm)) return -2; if (day > 0 || sec > 0) return 1; if (day < 0 || sec < 0) return -1; return 0; }
int check_time(long offset) { struct tm tm1, tm2, o1; int off_day, off_sec; long toffset; time_t t1, t2; time(&t1); t2 = t1 + offset; OPENSSL_gmtime(&t2, &tm2); OPENSSL_gmtime(&t1, &tm1); o1 = tm1; OPENSSL_gmtime_adj(&tm1, 0, offset); if ((tm1.tm_year != tm2.tm_year) || (tm1.tm_mon != tm2.tm_mon) || (tm1.tm_mday != tm2.tm_mday) || (tm1.tm_hour != tm2.tm_hour) || (tm1.tm_min != tm2.tm_min) || (tm1.tm_sec != tm2.tm_sec)) { fprintf(stderr, "TIME ERROR!!\n"); fprintf(stderr, "Time1: %d/%d/%d, %d:%02d:%02d\n", tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900, tm2.tm_hour, tm2.tm_min, tm2.tm_sec); fprintf(stderr, "Time2: %d/%d/%d, %d:%02d:%02d\n", tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900, tm1.tm_hour, tm1.tm_min, tm1.tm_sec); return 0; } OPENSSL_gmtime_diff(&o1, &tm1, &off_day, &off_sec); toffset = (long)off_day * SECS_PER_DAY + off_sec; if (offset != toffset) { fprintf(stderr, "TIME OFFSET ERROR!!\n"); fprintf(stderr, "Expected %ld, Got %ld (%d:%d)\n", offset, toffset, off_day, off_sec); return 0; } return 1; }
int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) { struct tm stm, ttm; int day, sec; if (!asn1_utctime_to_tm(&stm, s)) return -2; if (!OPENSSL_gmtime(&t, &ttm)) return -2; if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm)) return -2; if (day > 0) return 1; if (day < 0) return -1; if (sec > 0) return 1; if (sec < 0) return -1; return 0; }