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