aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/asn1/a_time.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2001-02-03 19:20:45 +0000
committerDr. Stephen Henson <steve@openssl.org>2001-02-03 19:20:45 +0000
commit02e4fbed3d256f4f1fffff84f307a336b50fae1f (patch)
tree9bc65efbadd271dc81ed2b2992d1b741b3219cd4 /crypto/asn1/a_time.c
parent7403c34b0b511e0dd0e31eeb7008abc566dd6b82 (diff)
downloadopenssl-02e4fbed3d256f4f1fffff84f307a336b50fae1f.tar.gz
Various OCSP responder utility functions.
Delete obsolete OCSP functions. Largely untested at present...
Diffstat (limited to 'crypto/asn1/a_time.c')
-rw-r--r--crypto/asn1/a_time.c46
1 files changed, 46 insertions, 0 deletions
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;
+ }