diff options
Diffstat (limited to 'src/regress/lib')
| -rw-r--r-- | src/regress/lib/libcrypto/asn1/asn1time.c | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1time.c b/src/regress/lib/libcrypto/asn1/asn1time.c index c6e13b0b20..f21c284e1c 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.18 2023/10/02 09:42:58 tb Exp $ */ | 1 | /* $OpenBSD: asn1time.c,v 1.19 2023/10/02 10:40:43 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -473,6 +473,80 @@ asn1_time_test(int test_no, const struct asn1_time_test *att, int type) | |||
| 473 | return (failure); | 473 | return (failure); |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | static int | ||
| 477 | time_t_cmp(time_t t1, time_t t2) | ||
| 478 | { | ||
| 479 | if (t1 < t2) | ||
| 480 | return -1; | ||
| 481 | if (t2 < t1) | ||
| 482 | return 1; | ||
| 483 | return 0; | ||
| 484 | } | ||
| 485 | |||
| 486 | static int | ||
| 487 | asn1_time_compare_families(const struct asn1_time_test *fam1, size_t fam1_size, | ||
| 488 | const struct asn1_time_test *fam2, size_t fam2_size) | ||
| 489 | { | ||
| 490 | const struct asn1_time_test *att1, *att2; | ||
| 491 | ASN1_TIME *t1 = NULL, *t2 = NULL; | ||
| 492 | size_t i, j; | ||
| 493 | int asn1_cmp, time_cmp; | ||
| 494 | int comparison_failure = 0; | ||
| 495 | int failure = 1; | ||
| 496 | |||
| 497 | if ((t1 = ASN1_TIME_new()) == NULL) | ||
| 498 | goto done; | ||
| 499 | if ((t2 = ASN1_TIME_new()) == NULL) | ||
| 500 | goto done; | ||
| 501 | |||
| 502 | for (i = 0; i < fam1_size; i++) { | ||
| 503 | att1 = &fam1[i]; | ||
| 504 | |||
| 505 | if (!ASN1_TIME_set_string(t1, att1->str)) | ||
| 506 | goto done; | ||
| 507 | for (j = 0; j < fam2_size; j++) { | ||
| 508 | att2 = &fam2[j]; | ||
| 509 | |||
| 510 | if (!ASN1_TIME_set_string(t2, att2->str)) | ||
| 511 | goto done; | ||
| 512 | |||
| 513 | time_cmp = time_t_cmp(att1->time, att2->time); | ||
| 514 | asn1_cmp = ASN1_TIME_compare(t1, t2); | ||
| 515 | |||
| 516 | if (time_cmp != asn1_cmp) { | ||
| 517 | fprintf(stderr, "%s vs. %s: want %d, got %d\n", | ||
| 518 | att1->str, att2->str, time_cmp, asn1_cmp); | ||
| 519 | comparison_failure |= 1; | ||
| 520 | } | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 524 | failure = comparison_failure; | ||
| 525 | |||
| 526 | done: | ||
| 527 | ASN1_TIME_free(t1); | ||
| 528 | ASN1_TIME_free(t2); | ||
| 529 | |||
| 530 | return failure; | ||
| 531 | } | ||
| 532 | |||
| 533 | static int | ||
| 534 | asn1_time_compare_test(void) | ||
| 535 | { | ||
| 536 | const struct asn1_time_test *gen = asn1_gentime_tests; | ||
| 537 | size_t gen_size = N_GENTIME_TESTS; | ||
| 538 | const struct asn1_time_test *utc = asn1_utctime_tests; | ||
| 539 | size_t utc_size = N_UTCTIME_TESTS; | ||
| 540 | int failed = 0; | ||
| 541 | |||
| 542 | failed |= asn1_time_compare_families(gen, gen_size, gen, gen_size); | ||
| 543 | failed |= asn1_time_compare_families(gen, gen_size, utc, utc_size); | ||
| 544 | failed |= asn1_time_compare_families(utc, utc_size, gen, gen_size); | ||
| 545 | failed |= asn1_time_compare_families(utc, utc_size, utc, utc_size); | ||
| 546 | |||
| 547 | return failed; | ||
| 548 | } | ||
| 549 | |||
| 476 | int | 550 | int |
| 477 | main(int argc, char **argv) | 551 | main(int argc, char **argv) |
| 478 | { | 552 | { |
| @@ -514,6 +588,9 @@ main(int argc, char **argv) | |||
| 514 | failed |= asn1_time_test(i, att, V_ASN1_GENERALIZEDTIME); | 588 | failed |= asn1_time_test(i, att, V_ASN1_GENERALIZEDTIME); |
| 515 | } | 589 | } |
| 516 | 590 | ||
| 591 | fprintf(stderr, "ASN1_TIME_compare tests...\n"); | ||
| 592 | failed |= asn1_time_compare_test(); | ||
| 593 | |||
| 517 | /* Check for a leak in ASN1_TIME_normalize(). */ | 594 | /* Check for a leak in ASN1_TIME_normalize(). */ |
| 518 | failed |= ASN1_TIME_normalize(NULL) != 0; | 595 | failed |= ASN1_TIME_normalize(NULL) != 0; |
| 519 | 596 | ||
