int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) { if (d->type != V_ASN1_GENERALIZEDTIME) return (0); return (d->type == ASN1_time_parse(d->data, d->length, NULL, d->type)); }
ASN1_GENERALIZEDTIME * ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) { ASN1_GENERALIZEDTIME *tmp = NULL; struct tm tm; char *str; if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME) return (NULL); memset(&tm, 0, sizeof(tm)); if (t->type != ASN1_time_parse(t->data, t->length, &tm, t->type)) return (NULL); if ((str = gentime_string_from_tm(&tm)) == NULL) return (NULL); if (out != NULL) tmp = *out; if (tmp == NULL && (tmp = ASN1_GENERALIZEDTIME_new()) == NULL) { free(str); return (NULL); } if (out != NULL) *out = tmp; free(tmp->data); tmp->data = str; tmp->length = strlen(str); return (tmp); }
int ASN1_TIME_check(ASN1_TIME *t) { if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME) return (0); return (t->type == ASN1_time_parse(t->data, t->length, NULL, t->type)); }
static time_t parse_ocsp_time(ASN1_GENERALIZEDTIME *gt) { struct tm tm; time_t rv = -1; if (gt == NULL) return -1; /* RFC 6960 specifies that all times in OCSP must be GENERALIZEDTIME */ if (ASN1_time_parse(gt->data, gt->length, &tm, V_ASN1_GENERALIZEDTIME) == -1) return -1; if ((rv = timegm(&tm)) == -1) return -1; return rv; }
int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t2) { struct tm tm1, tm2; /* * This function has never handled failure conditions properly * and should be deprecated. The OpenSSL version used to * simply follow NULL pointers on failure. BoringSSL and * OpenSSL now make it return -2 on failure. * * The danger is that users of this function will not * differentiate the -2 failure case from t1 < t2. */ if (ASN1_time_parse(s->data, s->length, &tm1, V_ASN1_UTCTIME) == -1) return (-2); /* XXX */ if (gmtime_r(&t2, &tm2) == NULL) return (-2); /* XXX */ return ASN1_time_tm_cmp(&tm1, &tm2); }
static int ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode) { int type; char *tmp; if ((type = ASN1_time_parse(str, strlen(str), NULL, mode)) == -1) return (0); if (mode != 0 && mode != type) return (0); if (s == NULL) return (1); if ((tmp = strdup(str)) == NULL) return (0); free(s->data); s->data = tmp; s->length = strlen(tmp); s->type = type; return (1); }