| 1 | /*
|
|---|
| 2 | * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
|
|---|
| 3 | * (Royal Institute of Technology, Stockholm, Sweden).
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
|
|---|
| 7 | *
|
|---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 9 | * modification, are permitted provided that the following conditions
|
|---|
| 10 | * are met:
|
|---|
| 11 | *
|
|---|
| 12 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 14 | *
|
|---|
| 15 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 16 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 17 | * documentation and/or other materials provided with the distribution.
|
|---|
| 18 | *
|
|---|
| 19 | * 3. Neither the name of the Institute nor the names of its contributors
|
|---|
| 20 | * may be used to endorse or promote products derived from this software
|
|---|
| 21 | * without specific prior written permission.
|
|---|
| 22 | *
|
|---|
| 23 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|---|
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|---|
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|---|
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|---|
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|---|
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|---|
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|---|
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|---|
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|---|
| 33 | * SUCH DAMAGE.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <config.h>
|
|---|
| 37 |
|
|---|
| 38 | #include <stdio.h>
|
|---|
| 39 | #include <string.h>
|
|---|
| 40 | #include <err.h>
|
|---|
| 41 | #include <roken.h>
|
|---|
| 42 |
|
|---|
| 43 | #include <asn1-common.h>
|
|---|
| 44 | #include <asn1_err.h>
|
|---|
| 45 | #include <der.h>
|
|---|
| 46 | #include <test_asn1.h>
|
|---|
| 47 |
|
|---|
| 48 | #include "check-common.h"
|
|---|
| 49 |
|
|---|
| 50 | static int
|
|---|
| 51 | cmp_dummy (void *a, void *b)
|
|---|
| 52 | {
|
|---|
| 53 | return 0;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | static int
|
|---|
| 57 | test_seqofseq(void)
|
|---|
| 58 | {
|
|---|
| 59 | struct test_case tests[] = {
|
|---|
| 60 | { NULL, 2,
|
|---|
| 61 | "\x30\x00",
|
|---|
| 62 | "seqofseq 0" },
|
|---|
| 63 | { NULL, 9,
|
|---|
| 64 | "\x30\x07\x30\x05\xa0\x03\x02\x01\x00",
|
|---|
| 65 | "seqofseq 1" },
|
|---|
| 66 | { NULL, 16,
|
|---|
| 67 | "\x30\x0e\x30\x05\xa0\x03\x02\x01\x00\x30\x05\xa0\x03\x02\x01\x01",
|
|---|
| 68 | "seqofseq 2" }
|
|---|
| 69 | };
|
|---|
| 70 |
|
|---|
| 71 | int ret = 0, ntests = sizeof(tests) / sizeof(*tests);
|
|---|
| 72 | TESTSeqOfSeq c0, c1, c2;
|
|---|
| 73 | struct TESTSeqOfSeq_val i[2];
|
|---|
| 74 |
|
|---|
| 75 | i[0].zero = 0;
|
|---|
| 76 | i[1].zero = 1;
|
|---|
| 77 |
|
|---|
| 78 | c0.len = 0;
|
|---|
| 79 | c0.val = NULL;
|
|---|
| 80 | tests[0].val = &c0;
|
|---|
| 81 |
|
|---|
| 82 | c1.len = 1;
|
|---|
| 83 | c1.val = i;
|
|---|
| 84 | tests[1].val = &c1;
|
|---|
| 85 |
|
|---|
| 86 | c2.len = 2;
|
|---|
| 87 | c2.val = i;
|
|---|
| 88 | tests[2].val = &c2;
|
|---|
| 89 |
|
|---|
| 90 | ret += generic_test (tests, ntests, sizeof(TESTSeqOfSeq),
|
|---|
| 91 | (generic_encode)encode_TESTSeqOfSeq,
|
|---|
| 92 | (generic_length)length_TESTSeqOfSeq,
|
|---|
| 93 | (generic_decode)decode_TESTSeqOfSeq,
|
|---|
| 94 | (generic_free)free_TESTSeqOfSeq,
|
|---|
| 95 | cmp_dummy,
|
|---|
| 96 | NULL);
|
|---|
| 97 | return ret;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | static int
|
|---|
| 101 | test_seqofseq2(void)
|
|---|
| 102 | {
|
|---|
| 103 | struct test_case tests[] = {
|
|---|
| 104 | { NULL, 2,
|
|---|
| 105 | "\x30\x00",
|
|---|
| 106 | "seqofseq2 0" },
|
|---|
| 107 | { NULL, 11,
|
|---|
| 108 | "\x30\x09\x30\x07\xa0\x05\x1b\x03\x65\x74\x74",
|
|---|
| 109 | "seqofseq2 1" },
|
|---|
| 110 | { NULL, 21,
|
|---|
| 111 | "\x30\x13\x30\x07\xa0\x05\x1b\x03\x65\x74\x74\x30\x08\xa0"
|
|---|
| 112 | "\x06\x1b\x04\x74\x76\x61\x61",
|
|---|
| 113 | "seqofseq2 2" }
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | int ret = 0, ntests = sizeof(tests) / sizeof(*tests);
|
|---|
| 117 | TESTSeqOfSeq2 c0, c1, c2;
|
|---|
| 118 | struct TESTSeqOfSeq2_val i[2];
|
|---|
| 119 |
|
|---|
| 120 | i[0].string = "ett";
|
|---|
| 121 | i[1].string = "tvaa";
|
|---|
| 122 |
|
|---|
| 123 | c0.len = 0;
|
|---|
| 124 | c0.val = NULL;
|
|---|
| 125 | tests[0].val = &c0;
|
|---|
| 126 |
|
|---|
| 127 | c1.len = 1;
|
|---|
| 128 | c1.val = i;
|
|---|
| 129 | tests[1].val = &c1;
|
|---|
| 130 |
|
|---|
| 131 | c2.len = 2;
|
|---|
| 132 | c2.val = i;
|
|---|
| 133 | tests[2].val = &c2;
|
|---|
| 134 |
|
|---|
| 135 | ret += generic_test (tests, ntests, sizeof(TESTSeqOfSeq2),
|
|---|
| 136 | (generic_encode)encode_TESTSeqOfSeq2,
|
|---|
| 137 | (generic_length)length_TESTSeqOfSeq2,
|
|---|
| 138 | (generic_decode)decode_TESTSeqOfSeq2,
|
|---|
| 139 | (generic_free)free_TESTSeqOfSeq2,
|
|---|
| 140 | cmp_dummy,
|
|---|
| 141 | NULL);
|
|---|
| 142 | return ret;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | static int
|
|---|
| 146 | test_seqof2(void)
|
|---|
| 147 | {
|
|---|
| 148 | struct test_case tests[] = {
|
|---|
| 149 | { NULL, 4,
|
|---|
| 150 | "\x30\x02\x30\x00",
|
|---|
| 151 | "seqof2 1" },
|
|---|
| 152 | { NULL, 9,
|
|---|
| 153 | "\x30\x07\x30\x05\x1b\x03\x66\x6f\x6f",
|
|---|
| 154 | "seqof2 2" },
|
|---|
| 155 | { NULL, 14,
|
|---|
| 156 | "\x30\x0c\x30\x0a\x1b\x03\x66\x6f\x6f\x1b\x03\x62\x61\x72",
|
|---|
| 157 | "seqof2 3" }
|
|---|
| 158 | };
|
|---|
| 159 |
|
|---|
| 160 | int ret = 0, ntests = sizeof(tests) / sizeof(*tests);
|
|---|
| 161 | TESTSeqOf2 c0, c1, c2;
|
|---|
| 162 | heim_general_string i[2];
|
|---|
| 163 |
|
|---|
| 164 | i[0] = "foo";
|
|---|
| 165 | i[1] = "bar";
|
|---|
| 166 |
|
|---|
| 167 | c0.strings.val = NULL;
|
|---|
| 168 | c0.strings.len = 0;
|
|---|
| 169 | tests[0].val = &c0;
|
|---|
| 170 |
|
|---|
| 171 | c1.strings.len = 1;
|
|---|
| 172 | c1.strings.val = i;
|
|---|
| 173 | tests[1].val = &c1;
|
|---|
| 174 |
|
|---|
| 175 | c2.strings.len = 2;
|
|---|
| 176 | c2.strings.val = i;
|
|---|
| 177 | tests[2].val = &c2;
|
|---|
| 178 |
|
|---|
| 179 | ret += generic_test (tests, ntests, sizeof(TESTSeqOf2),
|
|---|
| 180 | (generic_encode)encode_TESTSeqOf2,
|
|---|
| 181 | (generic_length)length_TESTSeqOf2,
|
|---|
| 182 | (generic_decode)decode_TESTSeqOf2,
|
|---|
| 183 | (generic_free)free_TESTSeqOf2,
|
|---|
| 184 | cmp_dummy,
|
|---|
| 185 | NULL);
|
|---|
| 186 | return ret;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | static int
|
|---|
| 190 | test_seqof3(void)
|
|---|
| 191 | {
|
|---|
| 192 | struct test_case tests[] = {
|
|---|
| 193 | { NULL, 2,
|
|---|
| 194 | "\x30\x00",
|
|---|
| 195 | "seqof3 0" },
|
|---|
| 196 | { NULL, 4,
|
|---|
| 197 | "\x30\x02\x30\x00",
|
|---|
| 198 | "seqof3 1" },
|
|---|
| 199 | { NULL, 9,
|
|---|
| 200 | "\x30\x07\x30\x05\x1b\x03\x66\x6f\x6f",
|
|---|
| 201 | "seqof3 2" },
|
|---|
| 202 | { NULL, 14,
|
|---|
| 203 | "\x30\x0c\x30\x0a\x1b\x03\x66\x6f\x6f\x1b\x03\x62\x61\x72",
|
|---|
| 204 | "seqof3 3" }
|
|---|
| 205 | };
|
|---|
| 206 |
|
|---|
| 207 | int ret = 0, ntests = sizeof(tests) / sizeof(*tests);
|
|---|
| 208 | TESTSeqOf3 c0, c1, c2, c3;
|
|---|
| 209 | struct TESTSeqOf3_strings s1, s2, s3;
|
|---|
| 210 | heim_general_string i[2];
|
|---|
| 211 |
|
|---|
| 212 | i[0] = "foo";
|
|---|
| 213 | i[1] = "bar";
|
|---|
| 214 |
|
|---|
| 215 | c0.strings = NULL;
|
|---|
| 216 | tests[0].val = &c0;
|
|---|
| 217 |
|
|---|
| 218 | s1.val = NULL;
|
|---|
| 219 | s1.len = 0;
|
|---|
| 220 | c1.strings = &s1;
|
|---|
| 221 | tests[1].val = &c1;
|
|---|
| 222 |
|
|---|
| 223 | s2.len = 1;
|
|---|
| 224 | s2.val = i;
|
|---|
| 225 | c2.strings = &s2;
|
|---|
| 226 | tests[2].val = &c2;
|
|---|
| 227 |
|
|---|
| 228 | s3.len = 2;
|
|---|
| 229 | s3.val = i;
|
|---|
| 230 | c3.strings = &s3;
|
|---|
| 231 | tests[3].val = &c3;
|
|---|
| 232 |
|
|---|
| 233 | ret += generic_test (tests, ntests, sizeof(TESTSeqOf3),
|
|---|
| 234 | (generic_encode)encode_TESTSeqOf3,
|
|---|
| 235 | (generic_length)length_TESTSeqOf3,
|
|---|
| 236 | (generic_decode)decode_TESTSeqOf3,
|
|---|
| 237 | (generic_free)free_TESTSeqOf3,
|
|---|
| 238 | cmp_dummy,
|
|---|
| 239 | NULL);
|
|---|
| 240 | return ret;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 | int
|
|---|
| 245 | main(int argc, char **argv)
|
|---|
| 246 | {
|
|---|
| 247 | int ret = 0;
|
|---|
| 248 |
|
|---|
| 249 | ret += test_seqofseq();
|
|---|
| 250 | ret += test_seqofseq2();
|
|---|
| 251 | ret += test_seqof2();
|
|---|
| 252 | ret += test_seqof3();
|
|---|
| 253 |
|
|---|
| 254 | return ret;
|
|---|
| 255 | }
|
|---|