diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libssl/bytestring/bytestringtest.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/regress/lib/libssl/bytestring/bytestringtest.c b/src/regress/lib/libssl/bytestring/bytestringtest.c index 05ca27e8b5..65b638132a 100644 --- a/src/regress/lib/libssl/bytestring/bytestringtest.c +++ b/src/regress/lib/libssl/bytestring/bytestringtest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bytestringtest.c,v 1.5 2015/06/16 06:37:58 doug Exp $ */ | 1 | /* $OpenBSD: bytestringtest.c,v 1.6 2015/06/17 07:15:52 doug Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014, Google Inc. | 3 | * Copyright (c) 2014, Google Inc. |
| 4 | * | 4 | * |
| @@ -671,6 +671,72 @@ test_asn1_uint64(void) | |||
| 671 | return 1; | 671 | return 1; |
| 672 | } | 672 | } |
| 673 | 673 | ||
| 674 | static int | ||
| 675 | test_offset(void) | ||
| 676 | { | ||
| 677 | uint8_t v; | ||
| 678 | static const uint8_t input[] = {1, 2, 3, 4, 5}; | ||
| 679 | CBS data; | ||
| 680 | |||
| 681 | CBS_init(&data, input, sizeof(input)); | ||
| 682 | if (sizeof(input) != 5) | ||
| 683 | return 0; | ||
| 684 | |||
| 685 | if (!(CBS_len(&data) == 5 && CBS_offset(&data) == 0 && | ||
| 686 | CBS_get_u8(&data, &v) && v == 1 && | ||
| 687 | CBS_len(&data) == 4 && CBS_offset(&data) == 1 && | ||
| 688 | CBS_skip(&data, 2) && | ||
| 689 | CBS_len(&data) == 2 && CBS_offset(&data) == 3 && | ||
| 690 | CBS_get_u8(&data, &v) && v == 4 && | ||
| 691 | CBS_get_u8(&data, &v) && v == 5 && | ||
| 692 | CBS_len(&data) == 0 && CBS_offset(&data) == 5 && | ||
| 693 | !CBS_skip(&data, 1))) | ||
| 694 | return 0; | ||
| 695 | |||
| 696 | CBS_init(&data, input, sizeof(input)); | ||
| 697 | if (!(CBS_skip(&data, 2) && | ||
| 698 | CBS_len(&data) == 3 && CBS_offset(&data) == 2 && | ||
| 699 | CBS_skip(&data, 3) && | ||
| 700 | CBS_len(&data) == 0 && CBS_offset(&data) == 5 && | ||
| 701 | !CBS_get_u8(&data, &v))) | ||
| 702 | return 0; | ||
| 703 | |||
| 704 | return 1; | ||
| 705 | } | ||
| 706 | |||
| 707 | static int | ||
| 708 | test_write_bytes(void) | ||
| 709 | { | ||
| 710 | int ret = 0; | ||
| 711 | uint8_t v; | ||
| 712 | size_t len; | ||
| 713 | static const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'}; | ||
| 714 | CBS data; | ||
| 715 | char *tmp = NULL; | ||
| 716 | |||
| 717 | if ((tmp = malloc(sizeof(input))) == NULL) { | ||
| 718 | fprintf(stderr, "failed to malloc\n"); | ||
| 719 | goto err; | ||
| 720 | } | ||
| 721 | memset(tmp, 100, sizeof(input)); | ||
| 722 | |||
| 723 | CBS_init(&data, input, sizeof(input)); | ||
| 724 | if (!(CBS_len(&data) == 6 && CBS_offset(&data) == 0 && | ||
| 725 | CBS_get_u8(&data, &v) && v == 102 /* f */ && | ||
| 726 | CBS_skip(&data, 1) && | ||
| 727 | !CBS_skip(&data, 15) && | ||
| 728 | CBS_write_bytes(&data, tmp, sizeof(input), &len) && | ||
| 729 | len == 4 && memcmp(input + 2, tmp, len) == 0 && | ||
| 730 | tmp[4] == 100 && tmp[5] == 100)) | ||
| 731 | goto err; | ||
| 732 | |||
| 733 | ret = 1; | ||
| 734 | |||
| 735 | err: | ||
| 736 | free(tmp); | ||
| 737 | return ret; | ||
| 738 | } | ||
| 739 | |||
| 674 | int | 740 | int |
| 675 | main(void) | 741 | main(void) |
| 676 | { | 742 | { |
| @@ -687,7 +753,9 @@ main(void) | |||
| 687 | !test_cbb_asn1() || | 753 | !test_cbb_asn1() || |
| 688 | !test_indefinite_convert() || | 754 | !test_indefinite_convert() || |
| 689 | !test_asn1_uint64() || | 755 | !test_asn1_uint64() || |
| 690 | !test_get_optional_asn1_bool()) | 756 | !test_get_optional_asn1_bool() || |
| 757 | !test_offset() || | ||
| 758 | !test_write_bytes()) | ||
| 691 | return 1; | 759 | return 1; |
| 692 | 760 | ||
| 693 | printf("PASS\n"); | 761 | printf("PASS\n"); |
