diff options
author | jsing <> | 2022-06-25 15:41:14 +0000 |
---|---|---|
committer | jsing <> | 2022-06-25 15:41:14 +0000 |
commit | 054c5de2e852004e06211ff00af4c880504a256f (patch) | |
tree | 691a2bfab38a450264c16f3b5abff96d5e8fffa7 /src | |
parent | 3ab5d00cdb582673304e9a788e751bb52462af01 (diff) | |
download | openbsd-054c5de2e852004e06211ff00af4c880504a256f.tar.gz openbsd-054c5de2e852004e06211ff00af4c880504a256f.tar.bz2 openbsd-054c5de2e852004e06211ff00af4c880504a256f.zip |
Add regress for ASN1_INTEGER_{get,set}_{u,}int64()
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/asn1/asn1basic.c | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c index 543ee93ee8..e46f9430a6 100644 --- a/src/regress/lib/libcrypto/asn1/asn1basic.c +++ b/src/regress/lib/libcrypto/asn1/asn1basic.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1basic.c,v 1.7 2022/06/25 13:57:17 jsing Exp $ */ | 1 | /* $OpenBSD: asn1basic.c,v 1.8 2022/06/25 15:41:14 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -460,6 +460,107 @@ asn1_integer_decode_test(struct asn1_integer_test *ait) | |||
460 | } | 460 | } |
461 | 461 | ||
462 | static int | 462 | static int |
463 | asn1_integer_set_val_test(void) | ||
464 | { | ||
465 | ASN1_INTEGER *aint = NULL; | ||
466 | uint64_t uval; | ||
467 | int64_t val; | ||
468 | int failed = 1; | ||
469 | |||
470 | if ((aint = ASN1_INTEGER_new()) == NULL) { | ||
471 | fprintf(stderr, "FAIL: ASN1_INTEGER_new() == NULL\n"); | ||
472 | goto failed; | ||
473 | } | ||
474 | |||
475 | if (!ASN1_INTEGER_set_uint64(aint, 0)) { | ||
476 | fprintf(stderr, "FAIL: ASN_INTEGER_set_uint64() failed with " | ||
477 | "0\n"); | ||
478 | goto failed; | ||
479 | } | ||
480 | if (!ASN1_INTEGER_get_uint64(&uval, aint)) { | ||
481 | fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " | ||
482 | "0\n"); | ||
483 | goto failed; | ||
484 | } | ||
485 | if (uval != 0) { | ||
486 | fprintf(stderr, "FAIL: uval != 0\n"); | ||
487 | goto failed; | ||
488 | } | ||
489 | |||
490 | if (!ASN1_INTEGER_set_uint64(aint, UINT64_MAX)) { | ||
491 | fprintf(stderr, "FAIL: ASN_INTEGER_set_uint64() failed with " | ||
492 | "UINT64_MAX\n"); | ||
493 | goto failed; | ||
494 | } | ||
495 | if (!ASN1_INTEGER_get_uint64(&uval, aint)) { | ||
496 | fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " | ||
497 | "UINT64_MAX\n"); | ||
498 | goto failed; | ||
499 | } | ||
500 | if (uval != UINT64_MAX) { | ||
501 | fprintf(stderr, "FAIL: uval != UINT64_MAX\n"); | ||
502 | goto failed; | ||
503 | } | ||
504 | if (ASN1_INTEGER_get_int64(&val, aint)) { | ||
505 | fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() succeeded " | ||
506 | "with UINT64_MAX\n"); | ||
507 | goto failed; | ||
508 | } | ||
509 | |||
510 | if (!ASN1_INTEGER_set_int64(aint, INT64_MIN)) { | ||
511 | fprintf(stderr, "FAIL: ASN_INTEGER_set_int64() failed with " | ||
512 | "INT64_MIN\n"); | ||
513 | goto failed; | ||
514 | } | ||
515 | if (!ASN1_INTEGER_get_int64(&val, aint)) { | ||
516 | fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " | ||
517 | "INT64_MIN\n"); | ||
518 | goto failed; | ||
519 | } | ||
520 | if (val != INT64_MIN) { | ||
521 | fprintf(stderr, "FAIL: val != INT64_MIN\n"); | ||
522 | goto failed; | ||
523 | } | ||
524 | if (ASN1_INTEGER_get_uint64(&uval, aint)) { | ||
525 | fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() succeeded " | ||
526 | "with INT64_MIN\n"); | ||
527 | goto failed; | ||
528 | } | ||
529 | |||
530 | if (!ASN1_INTEGER_set_int64(aint, INT64_MAX)) { | ||
531 | fprintf(stderr, "FAIL: ASN_INTEGER_set_int64() failed with " | ||
532 | "INT64_MAX\n"); | ||
533 | goto failed; | ||
534 | } | ||
535 | if (!ASN1_INTEGER_get_int64(&val, aint)) { | ||
536 | fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " | ||
537 | "INT64_MAX\n"); | ||
538 | goto failed; | ||
539 | } | ||
540 | if (val != INT64_MAX) { | ||
541 | fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " | ||
542 | "INT64_MAX\n"); | ||
543 | goto failed; | ||
544 | } | ||
545 | if (!ASN1_INTEGER_get_uint64(&uval, aint)) { | ||
546 | fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " | ||
547 | "INT64_MAX\n"); | ||
548 | goto failed; | ||
549 | } | ||
550 | if (uval != INT64_MAX) { | ||
551 | fprintf(stderr, "FAIL: uval != INT64_MAX\n"); | ||
552 | goto failed; | ||
553 | } | ||
554 | |||
555 | failed = 0; | ||
556 | |||
557 | failed: | ||
558 | ASN1_INTEGER_free(aint); | ||
559 | |||
560 | return failed; | ||
561 | } | ||
562 | |||
563 | static int | ||
463 | asn1_integer_cmp_test(void) | 564 | asn1_integer_cmp_test(void) |
464 | { | 565 | { |
465 | ASN1_INTEGER *a = NULL, *b = NULL; | 566 | ASN1_INTEGER *a = NULL, *b = NULL; |
@@ -549,6 +650,7 @@ asn1_integer_test(void) | |||
549 | } | 650 | } |
550 | 651 | ||
551 | failed |= asn1_integer_cmp_test(); | 652 | failed |= asn1_integer_cmp_test(); |
653 | failed |= asn1_integer_set_val_test(); | ||
552 | 654 | ||
553 | return failed; | 655 | return failed; |
554 | } | 656 | } |