From 02e4fbed3d256f4f1fffff84f307a336b50fae1f Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 3 Feb 2001 19:20:45 +0000 Subject: Various OCSP responder utility functions. Delete obsolete OCSP functions. Largely untested at present... --- crypto/asn1/a_time.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'crypto/asn1/a_time.c') diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index edc4929c36..03788a7d62 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -112,3 +112,49 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) return ASN1_UTCTIME_set(s, t); return ASN1_GENERALIZEDTIME_set(s,t); } + +int ASN1_TIME_check(ASN1_TIME *t) + { + if (t->type == V_ASN1_GENERALIZEDTIME) + return ASN1_GENERALIZEDTIME_check(t); + else if (t->type == V_ASN1_UTCTIME) + return ASN1_UTCTIME_check(t); + return 0; + } + +/* Convert an ASN1_TIME structure to GeneralizedTime */ +ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) + { + ASN1_GENERALIZEDTIME *ret; + char *str; + + if (!ASN1_TIME_check(t)) return NULL; + + if (!out || !*out) + { + if (!(ret = ASN1_GENERALIZEDTIME_new ())) + return NULL; + if (out) *out = ret; + } + else ret = *out; + + /* If already GeneralizedTime just copy across */ + if (t->type == V_ASN1_GENERALIZEDTIME) + { + if(!ASN1_STRING_set(ret, t->data, t->length)) + return NULL; + return ret; + } + + /* grow the string */ + if (!ASN1_STRING_set(ret, NULL, t->length + 2)) + return NULL; + /* Work out the century and prepend */ + str = (char *)t->data; + if (*str >= '5') strcpy(str, "19"); + else strcpy(str, "20"); + + strcat(str, (char *)t->data); + + return ret; + } -- cgit v1.2.3