summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1time.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1time.c b/src/regress/lib/libcrypto/asn1/asn1time.c
index ca54087dd7..6709e7af4a 100644
--- a/src/regress/lib/libcrypto/asn1/asn1time.c
+++ b/src/regress/lib/libcrypto/asn1/asn1time.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1time.c,v 1.12 2022/06/30 08:41:01 beck Exp $ */ 1/* $OpenBSD: asn1time.c,v 1.13 2022/06/30 09:13:49 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -100,6 +100,16 @@ struct asn1_time_test asn1_goodtime_tests[] = {
100 100
101struct asn1_time_test asn1_gentime_tests[] = { 101struct asn1_time_test asn1_gentime_tests[] = {
102 { 102 {
103 .str = "20161208193400Z",
104 .data = "20161208193400Z",
105 .time = 1481225640,
106 .der = {
107 0x18, 0x0f, 0x32, 0x30, 0x31, 0x36, 0x31, 0x32,
108 0x30, 0x38, 0x31, 0x39, 0x33, 0x34, 0x30, 0x30,
109 0x5a,
110 },
111 },
112 {
103 .str = "19700101000000Z", 113 .str = "19700101000000Z",
104 .data = "19700101000000Z", 114 .data = "19700101000000Z",
105 .time = 0, 115 .time = 0,
@@ -279,6 +289,7 @@ asn1_gentime_test(int test_no, struct asn1_time_test *att)
279 ASN1_GENERALIZEDTIME *gt = NULL; 289 ASN1_GENERALIZEDTIME *gt = NULL;
280 int failure = 1; 290 int failure = 1;
281 int len; 291 int len;
292 struct tm tm;
282 293
283 if (ASN1_GENERALIZEDTIME_set_string(NULL, att->str) != 1) { 294 if (ASN1_GENERALIZEDTIME_set_string(NULL, att->str) != 1) {
284 fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", 295 fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n",
@@ -297,6 +308,21 @@ asn1_gentime_test(int test_no, struct asn1_time_test *att)
297 if (asn1_compare_str(test_no, gt, att->str) != 0) 308 if (asn1_compare_str(test_no, gt, att->str) != 0)
298 goto done; 309 goto done;
299 310
311 if (ASN1_TIME_to_tm(gt, &tm) == 0) {
312 fprintf(stderr, "FAIL: test %i - ASN1_time_to_tm failed '%s'\n",
313 test_no, att->str);
314 goto done;
315 }
316
317 if (timegm(&tm) != att->time) {
318 /* things with crappy time_t should die in fire */
319 int64_t a = timegm(&tm);
320 int64_t b = att->time;
321 fprintf(stderr, "FAIL: test %i - times don't match, expected %lld got %lld\n",
322 test_no, b, a);
323 goto done;
324 }
325
300 if ((len = i2d_ASN1_GENERALIZEDTIME(gt, &p)) <= 0) { 326 if ((len = i2d_ASN1_GENERALIZEDTIME(gt, &p)) <= 0) {
301 fprintf(stderr, "FAIL: test %i - i2d_ASN1_GENERALIZEDTIME " 327 fprintf(stderr, "FAIL: test %i - i2d_ASN1_GENERALIZEDTIME "
302 "failed\n", test_no); 328 "failed\n", test_no);