summaryrefslogtreecommitdiff
path: root/crypto/asn1/a_utctm.c
diff options
context:
space:
mode:
authorPaul Yang <yang.yang@baishancloud.com>2017-07-30 20:14:58 -0400
committerRich Salz <rsalz@openssl.org>2017-07-30 20:14:58 -0400
commitf673c4f8f2a12bb8efcb0869646fdf0efd6bf30e (patch)
treedb79c9fd4f78c83b035e52626e3f2c8db8336211 /crypto/asn1/a_utctm.c
parent27eb9f23e60e5ed15651011f56eaf04591120630 (diff)
downloadopenssl-new-f673c4f8f2a12bb8efcb0869646fdf0efd6bf30e.tar.gz
Refactor ASN1_TIME_print functions
Check time string format before parsing Reduce more duplicated code By involving asn1_time_to_tm, we can now get information we mostly need to print a time string. This follows what was discussed at https://github.com/openssl/openssl/pull/4001#discussion_r129092251 Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4039)
Diffstat (limited to 'crypto/asn1/a_utctm.c')
-rw-r--r--crypto/asn1/a_utctm.c42
1 files changed, 3 insertions, 39 deletions
diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c
index 668efa48bb..1f24508ffd 100644
--- a/crypto/asn1/a_utctm.c
+++ b/crypto/asn1/a_utctm.c
@@ -129,45 +129,9 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
return 0;
}
-static const char _asn1_mon[12][4] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
{
- const char *v;
- int gmt = 0;
- int i;
- int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
-
- i = tm->length;
- v = (const char *)tm->data;
-
- if (i < 10)
- goto err;
- if (v[i - 1] == 'Z')
- gmt = 1;
- for (i = 0; i < 10; i++)
- if ((v[i] > '9') || (v[i] < '0'))
- goto err;
- y = (v[0] - '0') * 10 + (v[1] - '0');
- if (y < 50)
- y += 100;
- M = (v[2] - '0') * 10 + (v[3] - '0');
- if ((M > 12) || (M < 1))
- goto err;
- d = (v[4] - '0') * 10 + (v[5] - '0');
- h = (v[6] - '0') * 10 + (v[7] - '0');
- m = (v[8] - '0') * 10 + (v[9] - '0');
- if (tm->length >= 12 &&
- (v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9'))
- s = (v[10] - '0') * 10 + (v[11] - '0');
-
- return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
- _asn1_mon[M - 1], d, h, m, s, y + 1900,
- (gmt) ? " GMT" : "") > 0;
- err:
- BIO_write(bp, "Bad time value", 14);
- return 0;
+ if (tm->type != V_ASN1_UTCTIME)
+ return 0;
+ return ASN1_TIME_print(bp, tm);
}