1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 #include "manifest3_decode.h"
9 #include "manifest3_encode.h"
10 #include "zcbor_print.h"
11 
12 /* draft-ietf-suit-manifest-02 Example 0 */
13 uint8_t test_vector0_02[] = {
14 	0xa2, 0x01, 0x58, 0x54, 0xd2, 0x84, 0x43, 0xa1, 0x01,
15 	0x26, 0xa1, 0x04, 0x48, 0x74, 0x65, 0x73, 0x74, 0x20,
16 	0x6b, 0x65, 0x79, 0xf6, 0x58, 0x40, 0xeb, 0xec, 0xb6,
17 	0x6c, 0xbe, 0xcb, 0x19, 0xdc, 0xed, 0xac, 0xf8, 0x45,
18 	0x9c, 0x1a, 0x22, 0xa1, 0x45, 0x37, 0x81, 0xba, 0x98,
19 	0xd8, 0xff, 0xb9, 0xd4, 0xe2, 0x91, 0x2f, 0x29, 0xd2,
20 	0x3b, 0xac, 0x5a, 0xe3, 0xd5, 0x1f, 0x1f, 0xf0, 0xc1,
21 	0xb1, 0xdf, 0x05, 0xe2, 0x07, 0xca, 0x17, 0x48, 0x3a,
22 	0x57, 0xed, 0xe9, 0x14, 0xcf, 0x82, 0x6b, 0x73, 0x59,
23 	0x91, 0x37, 0x88, 0x1c, 0x83, 0x64, 0xc8, 0x02, 0x58,
24 	0x51, 0xa4, 0x01, 0x01, 0x02, 0x01, 0x03, 0x58, 0x40,
25 	0xa2, 0x02, 0x4c, 0x81, 0x82, 0x45, 0x46, 0x6c, 0x61,
26 	0x73, 0x68, 0x43, 0x00, 0x34, 0x01, 0x04, 0x58, 0x2e,
27 	0x82, 0x13, 0xa2, 0x0b, 0x58, 0x24, 0x82, 0x02, 0x58,
28 	0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
29 	0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01,
30 	0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc,
31 	0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x0c, 0x19, 0x87,
32 	0xd0, 0x0c, 0x47, 0x86, 0x0c, 0x00, 0x03, 0xf6, 0x17,
33 	0xf6
34 };
35 
36 /* draft-ietf-suit-manifest-03 Example 0 */
37 uint8_t test_vector0[] = {
38 	0xa1, 0x02, 0x58, 0x6c, 0xa5, 0x01, 0x01, 0x02,
39 	0x01, 0x03, 0x58, 0x5a, 0xa2, 0x02, 0x44, 0x81,
40 	0x81, 0x41, 0x00, 0x04, 0x58, 0x50, 0x86, 0x01,
41 	0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5, 0xad, 0x5f,
42 	0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4, 0xd4, 0x1f,
43 	0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf, 0x14, 0x25,
44 	0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b, 0x2d, 0x51,
45 	0xf2, 0xab, 0x45, 0x14, 0xa2, 0x0b, 0x82, 0x02,
46 	0x58, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
47 	0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
48 	0xee, 0xff, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
49 	0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
50 	0x32, 0x10, 0x0c, 0x19, 0x87, 0xd0, 0x0a, 0x43,
51 	0x82, 0x03, 0xf6, 0x0c, 0x43, 0x82, 0x17, 0xf6
52 };
53 
54 /* draft-ietf-suit-manifest-03 Example 1 */
55 uint8_t test_vector1[] = {
56 	0xa1, 0x03, 0x58, 0x8a, 0xa4, 0x01, 0x01, 0x02,
57 	0x02, 0x03, 0x58, 0x5a, 0xa2, 0x02, 0x44, 0x81,
58 	0x81, 0x41, 0x00, 0x04, 0x58, 0x50, 0x86, 0x01,
59 	0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5, 0xad, 0x5f,
60 	0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4, 0xd4, 0x1f,
61 	0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf, 0x14, 0x25,
62 	0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b, 0x2d, 0x51,
63 	0xf2, 0xab, 0x45, 0x14, 0xa2, 0x0b, 0x82, 0x02,
64 	0x58, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
65 	0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
66 	0xee, 0xff, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
67 	0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
68 	0x32, 0x10, 0x0c, 0x19, 0x87, 0xd0, 0x09, 0x58,
69 	0x25, 0x86, 0x13, 0xa1, 0x06, 0x78, 0x1b, 0x68,
70 	0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78,
71 	0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
72 	0x6d, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x62,
73 	0x69, 0x6e, 0x15, 0xf6, 0x03, 0xf6
74 };
75 
76 /* draft-ietf-suit-manifest-03 Example 2 */
77 uint8_t test_vector2[] = {
78 	0xa2, 0x02, 0x58, 0x70, 0x81, 0xd2, 0x84, 0x43,
79 	0xa1, 0x01, 0x26, 0xa0, 0x58, 0x24, 0x82, 0x02,
80 	0x58, 0x20, 0x70, 0xcf, 0x2a, 0x4f, 0xed, 0x64,
81 	0x06, 0x58, 0xad, 0xa6, 0xff, 0x33, 0xb5, 0x9a,
82 	0xf1, 0x92, 0xca, 0x22, 0xb4, 0x14, 0x2e, 0x9a,
83 	0xe9, 0xd8, 0xd9, 0xb0, 0x5f, 0x2b, 0x5a, 0x11,
84 	0x8c, 0xf3, 0x58, 0x40, 0xf6, 0xc9, 0x56, 0x81,
85 	0xef, 0x42, 0x98, 0x12, 0x88, 0xe1, 0x10, 0x04,
86 	0xa4, 0xb7, 0x2b, 0xe8, 0x0a, 0x37, 0x4b, 0xe1,
87 	0x3e, 0xfc, 0xcf, 0x5e, 0xc9, 0x4f, 0xa1, 0xad,
88 	0x2c, 0xa7, 0xd5, 0x51, 0x0d, 0x5f, 0xf4, 0x3c,
89 	0xea, 0xc6, 0x0e, 0x7d, 0xd3, 0x2d, 0x36, 0x14,
90 	0xbd, 0x03, 0x50, 0x76, 0x8f, 0x98, 0x5e, 0xff,
91 	0x8b, 0xa9, 0x93, 0x36, 0x25, 0xd2, 0x06, 0x28,
92 	0x6c, 0xf9, 0x83, 0x03, 0x58, 0x94, 0x01, 0x01,
93 	0x02, 0x03, 0x03, 0x58, 0x5a, 0xa2, 0x02, 0x44,
94 	0x81, 0x81, 0x41, 0x00, 0x04, 0x58, 0x50, 0x86,
95 	0x01, 0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5, 0xad,
96 	0x5f, 0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4, 0xd4,
97 	0x1f, 0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf, 0x14,
98 	0x25, 0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b, 0x2d,
99 	0x51, 0xf2, 0xab, 0x45, 0x14, 0xa2, 0x0b, 0x82,
100 	0x02, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
101 	0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
102 	0xee, 0xff, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
103 	0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
104 	0x32, 0x10, 0x0c, 0x19, 0x87, 0xd0, 0x09, 0x58,
105 	0x25, 0x86, 0x13, 0xa1, 0x06, 0x78, 0x1b, 0x68,
106 	0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78,
107 	0x61, 0x6d, 0x70, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
108 	0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x62, 0x69,
109 	0x6e, 0x15, 0xf6, 0x03, 0xf6, 0x0a, 0x43, 0x82,
110 	0x03, 0xf6, 0x0c, 0x43, 0x82, 0x17, 0xf6,
111 };
112 
113 /* draft-ietf-suit-manifest-03 Example 3 */
114 uint8_t test_vector3[] = {
115 	0xa2, 0x02, 0x58, 0x70, 0x81, 0xd2, 0x84, 0x43,
116 	0xa1, 0x01, 0x26, 0xa0, 0x58, 0x24, 0x82, 0x02,
117 	0x58, 0x20, 0xbb, 0x00, 0x8f, 0x57, 0xfd, 0x1b,
118 	0xab, 0xff, 0x8c, 0xc4, 0x32, 0xd1, 0x8c, 0x4c,
119 	0x9c, 0xfc, 0x69, 0xd7, 0xe8, 0xab, 0x76, 0xb0,
120 	0x7c, 0xc9, 0x10, 0xc6, 0xd0, 0x3e, 0xc5, 0x98,
121 	0xba, 0xab, 0x58, 0x40, 0x9e, 0x98, 0xc5, 0x8f,
122 	0xcd, 0x82, 0x66, 0x84, 0x43, 0xa0, 0x24, 0x9f,
123 	0xa5, 0xea, 0xb1, 0x04, 0x74, 0xa0, 0x99, 0x57,
124 	0x2d, 0xfb, 0x31, 0xc0, 0xd2, 0xad, 0xf7, 0x50,
125 	0xf5, 0x7c, 0x49, 0x87, 0xd4, 0x84, 0xba, 0xdf,
126 	0x85, 0x24, 0xa2, 0x0a, 0x9e, 0x92, 0xc4, 0x59,
127 	0x96, 0x98, 0xeb, 0x69, 0x62, 0x54, 0xd4, 0xc0,
128 	0xf7, 0x79, 0x47, 0xc8, 0xaf, 0x35, 0x3b, 0x54,
129 	0x46, 0x00, 0xea, 0x11, 0x03, 0x58, 0xd6, 0xa7,
130 	0x01, 0x01, 0x02, 0x04, 0x03, 0x58, 0x5f, 0xa2,
131 	0x02, 0x47, 0x82, 0x81, 0x41, 0x00, 0x81, 0x41,
132 	0x01, 0x04, 0x58, 0x52, 0x88, 0x0c, 0x00, 0x01,
133 	0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5, 0xad, 0x5f,
134 	0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4, 0xd4, 0x1f,
135 	0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf, 0x14, 0x25,
136 	0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b, 0x2d, 0x51,
137 	0xf2, 0xab, 0x45, 0x14, 0xa2, 0x0b, 0x82, 0x02,
138 	0x58, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
139 	0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
140 	0xee, 0xff, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
141 	0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
142 	0x32, 0x10, 0x0c, 0x19, 0x87, 0xd0, 0x09, 0x58,
143 	0x27, 0x88, 0x0c, 0x00, 0x13, 0xa1, 0x06, 0x78,
144 	0x1b, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
145 	0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
146 	0x63, 0x6f, 0x6d, 0x2f, 0x66, 0x69, 0x6c, 0x65,
147 	0x2e, 0x62, 0x69, 0x6e, 0x15, 0xf6, 0x03, 0xf6,
148 	0x0a, 0x45, 0x84, 0x0c, 0x00, 0x03, 0xf6, 0x0b,
149 	0x58, 0x34, 0x88, 0x0c, 0x01, 0x14, 0xa3, 0x0a,
150 	0x00, 0x0b, 0x82, 0x02, 0x58, 0x20, 0x00, 0x11,
151 	0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
152 	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23,
153 	0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc,
154 	0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x0c, 0x19,
155 	0x87, 0xd0, 0x16, 0xf6, 0x03, 0xf6, 0x0c, 0x45,
156 	0x84, 0x0c, 0x01, 0x17, 0xf6,
157 };
158 
159 /* draft-ietf-suit-manifest-03 Example 4 */
160 uint8_t test_vector4[] = {
161 	0xa2, 0x01, 0x58, 0x70, 0x81, 0xd2, 0x84, 0x43,
162 	0xa1, 0x01, 0x26, 0xa0, 0x58, 0x24, 0x82, 0x02,
163 	0x58, 0x20, 0xb9, 0x73, 0xe2, 0x42, 0x4d, 0x03,
164 	0xde, 0x20, 0xc5, 0x9c, 0xb7, 0x02,
165 	0x60, 0x7a, 0x83, 0x79, 0x6d, 0xd4, 0x65, 0x67,
166 	0x41, 0x15, 0xae, 0x84, 0xb3, 0xc2, 0xc4, 0x72,
167 	0x79, 0x4d, 0xbb, 0x8c, 0x58, 0x40, 0xbe, 0x0a,
168 	0xe3, 0xd3, 0x60, 0xe4, 0x6d, 0xd0,
169 	0x7f, 0x02, 0x54, 0x7f, 0xf1, 0x9e, 0x4a, 0x15,
170 	0x57, 0xb7, 0xbf, 0xce, 0x40, 0x17, 0x18, 0xad,
171 	0xe8, 0x20, 0x09, 0x18, 0xf1, 0x91, 0xa5, 0x0d,
172 	0xca, 0x84, 0x14, 0x87, 0x04, 0xf7,
173 	0x6d, 0x97, 0xa8, 0xc2, 0x39, 0x61, 0x51, 0x14,
174 	0xea, 0xb0, 0x61, 0x7e, 0x9f, 0xc9, 0xd4, 0xfa,
175 	0xea, 0xc1, 0x57, 0x2e, 0x7c, 0xae, 0x61, 0xe6,
176 	0x60, 0xc1, 0x02, 0x58, 0xd8, 0xa7,
177 	0x01, 0x01, 0x02, 0x05, 0x03, 0x58, 0x5f, 0xa2,
178 	0x02, 0x47, 0x82, 0x81, 0x41, 0x00, 0x81, 0x41,
179 	0x01, 0x04, 0x58, 0x52, 0x88, 0x0c, 0x00, 0x01,
180 	0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5,
181 	0xad, 0x5f, 0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4,
182 	0xd4, 0x1f, 0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf,
183 	0x14, 0x25, 0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b,
184 	0x2d, 0x51, 0xf2, 0xab, 0x45, 0x14,
185 	0xa2, 0x0b, 0x82, 0x02, 0x58, 0x20, 0x00, 0x11,
186 	0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
187 	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23,
188 	0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
189 	0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
190 	0x0c, 0x19, 0x87, 0xd0, 0x09, 0x58, 0x27, 0x88,
191 	0x0c, 0x00, 0x13, 0xa1, 0x06, 0x78, 0x1b, 0x68,
192 	0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
193 	0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
194 	0x63, 0x6f, 0x6d, 0x2f, 0x66, 0x69, 0x6c, 0x65,
195 	0x2e, 0x62, 0x69, 0x6e, 0x15, 0xf6, 0x03, 0xf6,
196 	0x0a, 0x45, 0x84, 0x0c, 0x00, 0x03,
197 	0xf6, 0x0b, 0x58, 0x36, 0x88, 0x0c, 0x01, 0x14,
198 	0xa4, 0x08, 0x01, 0x0a, 0x00, 0x0b, 0x82, 0x02,
199 	0x58, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
200 	0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
201 	0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23, 0x45, 0x67,
202 	0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98,
203 	0x76, 0x54, 0x32, 0x10, 0x0c, 0x19, 0x87, 0xd0,
204 	0x16, 0xf6, 0x03, 0xf6, 0x0c, 0x45,
205 	0x84, 0x0c, 0x01, 0x17, 0xf6
206 };
207 
208 const uint8_t *test_vector[] = {
209 	test_vector0_02,
210 	// test_vector0,
211 	// test_vector1,
212 	// test_vector2,
213 	// test_vector3,
214 	// test_vector4,
215 };
216 
217 uint32_t test_vector_len[] = {
218 	sizeof(test_vector0_02),
219 	// sizeof(test_vector0),
220 	// sizeof(test_vector1),
221 	// sizeof(test_vector2),
222 	// sizeof(test_vector3),
223 	// sizeof(test_vector4),
224 };
225 
226 uint32_t num_test_vectors = sizeof(test_vector)/sizeof(uint8_t*);
227 
228 
229 static uint8_t output[2000];
230 
test_command_sequence(struct zcbor_string * sequence_str,bool present,char * name)231 void test_command_sequence(struct zcbor_string *sequence_str,
232 			bool present, char *name)
233 {
234 	struct SUIT_Command_Sequence sequence1;
235 	struct zcbor_string *run_seq;
236 	bool run_seq_present;
237 	struct zcbor_string *try_each1;
238 	bool try_each1_present;
239 	struct zcbor_string *try_each2;
240 	bool try_each2_present;
241 	size_t out_len;
242 
243 	if (!present) {
244 		return;
245 	}
246 
247 	zcbor_log("\r\ntest %s\r\n", name);
248 
249 	memset(&sequence1, 0, sizeof(sequence1));
250 	int res = cbor_decode_SUIT_Command_Sequence(sequence_str->value,
251 		sequence_str->len,
252 		&sequence1, NULL);
253 	zassert_equal(ZCBOR_SUCCESS, res, NULL);
254 
255 
256 	res = cbor_encode_SUIT_Command_Sequence(output,
257 		sizeof(output),
258 		&sequence1, &out_len);
259 	zassert_equal(ZCBOR_SUCCESS, res, NULL);
260 	zassert_equal(sequence_str->len, out_len, "%d != %d\r\n", sequence_str->len, out_len);
261 	zassert_mem_equal(sequence_str->value,
262 		output,
263 		sequence_str->len,
264 		NULL);
265 
266 	for (uint32_t i = 0; i < sequence1.SUIT_Command_Sequence_union_count; i++) {
267 		struct SUIT_Directive_r *directive;
268 		bool directive_present;
269 		directive = &sequence1
270 			.SUIT_Command_Sequence_union[i]
271 			.SUIT_Command_Sequence_union_SUIT_Directive_m;
272 		directive_present = sequence1
273 			.SUIT_Command_Sequence_union[i]
274 			.SUIT_Command_Sequence_union_choice
275 			== SUIT_Command_Sequence_union_SUIT_Directive_m_c;
276 
277 		run_seq = &directive
278 			->SUIT_Directive_suit_directive_run_sequence_m_l_SUIT_Command_Sequence_bstr;
279 		run_seq_present = directive_present
280 			&& directive
281 			->SUIT_Directive_choice
282 			== SUIT_Directive_suit_directive_run_sequence_m_l_c;
283 		test_command_sequence(run_seq, run_seq_present, "run_seq");
284 
285 		for (uint32_t j = 0; j < directive
286 			->SUIT_Directive_suit_directive_try_each_m_l_SUIT_Directive_Try_Each_Argument_m
287 			.SUIT_Directive_Try_Each_Argument_SUIT_Command_Sequence_bstr_count; j++) {
288 
289 			try_each1 = &directive
290 				->SUIT_Directive_suit_directive_try_each_m_l_SUIT_Directive_Try_Each_Argument_m
291 				.SUIT_Directive_Try_Each_Argument_SUIT_Command_Sequence_bstr[j];
292 			try_each1_present = directive_present
293 				&& directive->SUIT_Directive_choice
294 				== SUIT_Directive_suit_directive_try_each_m_l_c;
295 			test_command_sequence(try_each1, try_each1_present, "try_each1");
296 		}
297 
298 		try_each2 = &directive
299 			->SUIT_Directive_suit_directive_try_each_m_l_SUIT_Directive_Try_Each_Argument_m
300 			.SUIT_Directive_Try_Each_Argument_union_SUIT_Command_Sequence_bstr;
301 		try_each2_present = directive_present
302 			&& directive->SUIT_Directive_choice
303 			== SUIT_Directive_suit_directive_try_each_m_l_c
304 			&& directive
305 			->SUIT_Directive_suit_directive_try_each_m_l_SUIT_Directive_Try_Each_Argument_m
306 			.SUIT_Directive_Try_Each_Argument_union_choice
307 			== SUIT_Directive_Try_Each_Argument_union_SUIT_Command_Sequence_bstr_c;
308 		test_command_sequence(try_each2, try_each2_present, "try_each2");
309 
310 	}
311 }
312 
test_manifest(const uint8_t * input,uint32_t len)313 void test_manifest(const uint8_t *input, uint32_t len)
314 {
315 	struct SUIT_Outer_Wrapper outerwrapper1 = {0};
316 	struct SUIT_Manifest *manifest;
317 	// struct SUIT_Component_Identifier *component;
318 	struct zcbor_string *dependency1;
319 	bool dependency1_present;
320 	struct zcbor_string *fetch1;
321 	bool fetch1_present;
322 	struct zcbor_string *install1;
323 	bool install1_present;
324 	struct zcbor_string *common_seq;
325 	bool common_seq_present;
326 	struct zcbor_string *dependency2;
327 	bool dependency2_present;
328 	struct zcbor_string *fetch2;
329 	bool fetch2_present;
330 	struct zcbor_string *install2;
331 	bool install2_present;
332 	struct zcbor_string *validate;
333 	bool validate_present;
334 	struct zcbor_string *load;
335 	bool load_present;
336 	struct zcbor_string *run;
337 	bool run_present;
338 	int res;
339 	size_t out_len;
340 
341 	zcbor_log("test_vector at: 0x%zx\r\n", (size_t)input);
342 	zcbor_log("test_vector end at: 0x%zx\r\n",
343 				((size_t)input) + len);
344 	res = cbor_decode_SUIT_Outer_Wrapper(input, len, &outerwrapper1, NULL);
345 	zassert_equal(ZCBOR_SUCCESS, res, "top-level decoding failed.");
346 
347 	dependency1 = &outerwrapper1
348 		.SUIT_Outer_Wrapper_suit_dependency_resolution
349 		.SUIT_Outer_Wrapper_suit_dependency_resolution;
350 	dependency1_present = outerwrapper1
351 		.SUIT_Outer_Wrapper_suit_dependency_resolution_present;
352 	test_command_sequence(dependency1, dependency1_present, "dependency1");
353 
354 	fetch1 = &outerwrapper1
355 		.SUIT_Outer_Wrapper_suit_payload_fetch
356 		.SUIT_Outer_Wrapper_suit_payload_fetch;
357 	fetch1_present = outerwrapper1
358 		.SUIT_Outer_Wrapper_suit_payload_fetch_present;
359 	test_command_sequence(fetch1, fetch1_present, "fetch1");
360 
361 	install1 = &outerwrapper1
362 		.SUIT_Outer_Wrapper_suit_install
363 		.SUIT_Outer_Wrapper_suit_install;
364 	install1_present = outerwrapper1
365 		.SUIT_Outer_Wrapper_suit_install_present;
366 	test_command_sequence(install1, install1_present, "install1");
367 
368 	manifest = &outerwrapper1
369 		.SUIT_Outer_Wrapper_SUIT_Manifest_Wrapped_m
370 		.SUIT_Manifest_Wrapped_suit_manifest_cbor;
371 
372 	common_seq = &manifest
373 		->SUIT_Manifest_suit_common
374 		.SUIT_Manifest_suit_common_cbor
375 		.SUIT_Common_suit_common_sequence
376 		.SUIT_Common_suit_common_sequence;
377 	common_seq_present = manifest
378 		->SUIT_Manifest_suit_common_present
379 		&& manifest
380 		->SUIT_Manifest_suit_common
381 		.SUIT_Manifest_suit_common_cbor
382 		.SUIT_Common_suit_common_sequence_present;
383 	test_command_sequence(common_seq, common_seq_present, "common_seq");
384 
385 	dependency2 = &manifest
386 		->SUIT_Manifest_suit_dependency_resolution
387 		.SUIT_Manifest_suit_dependency_resolution_SUIT_Command_Sequence_bstr;
388 	dependency2_present = manifest
389 		->SUIT_Manifest_suit_dependency_resolution_present
390 		&& manifest
391 		->SUIT_Manifest_suit_dependency_resolution
392 		.SUIT_Manifest_suit_dependency_resolution_choice ==
393 		SUIT_Manifest_suit_dependency_resolution_SUIT_Command_Sequence_bstr_c;
394 	test_command_sequence(dependency2, dependency2_present, "dependency2");
395 
396 	fetch2 = &manifest
397 		->SUIT_Manifest_suit_payload_fetch
398 		.SUIT_Manifest_suit_payload_fetch_SUIT_Command_Sequence_bstr;
399 	fetch2_present = manifest
400 		->SUIT_Manifest_suit_payload_fetch_present
401 		&& manifest
402 		->SUIT_Manifest_suit_payload_fetch
403 		.SUIT_Manifest_suit_payload_fetch_choice ==
404 		SUIT_Manifest_suit_payload_fetch_SUIT_Command_Sequence_bstr_c;
405 	test_command_sequence(fetch2, fetch2_present, "fetch2");
406 
407 	install2 = &manifest
408 		->SUIT_Manifest_suit_install
409 		.SUIT_Manifest_suit_install_SUIT_Command_Sequence_bstr;
410 	install2_present = manifest
411 		->SUIT_Manifest_suit_install_present
412 		&& manifest
413 		->SUIT_Manifest_suit_install
414 		.SUIT_Manifest_suit_install_choice ==
415 		SUIT_Manifest_suit_install_SUIT_Command_Sequence_bstr_c;
416 	test_command_sequence(install2, install2_present, "install2");
417 
418 	validate = &manifest
419 		->SUIT_Manifest_suit_validate
420 		.SUIT_Manifest_suit_validate;
421 	validate_present = manifest
422 		->SUIT_Manifest_suit_validate_present;
423 	test_command_sequence(validate, validate_present, "validate");
424 
425 	load = &manifest
426 		->SUIT_Manifest_suit_load
427 		.SUIT_Manifest_suit_load;
428 	load_present = manifest
429 		->SUIT_Manifest_suit_load_present;
430 	test_command_sequence(load, load_present, "load");
431 
432 	run = &manifest
433 		->SUIT_Manifest_suit_run
434 		.SUIT_Manifest_suit_run;
435 	run_present = manifest
436 		->SUIT_Manifest_suit_run_present;
437 	test_command_sequence(run, run_present, "run");
438 
439 	res = cbor_encode_SUIT_Outer_Wrapper(output,
440 					sizeof(output), &outerwrapper1, &out_len);
441 	zassert_equal(ZCBOR_SUCCESS, res, "top-level encoding failed.");
442 	zassert_equal(len, out_len, NULL);
443 	zassert_mem_equal(input, output, len, NULL);
444 }
445 
ZTEST(cbor_encode_test1,test_suit)446 ZTEST(cbor_encode_test1, test_suit)
447 {
448 	for(uint32_t i = 0; i < num_test_vectors; i++) {
449 		test_manifest(test_vector[i], test_vector_len[i]);
450 	}
451 }
452 
453 ZTEST_SUITE(cbor_encode_test1, NULL, NULL, NULL, NULL, NULL);
454