1 /*
2  * Generated using zcbor version 0.8.0
3  * https://github.com/NordicSemiconductor/zcbor
4  * Generated with a --default-max-qty of 3
5  */
6 
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <string.h>
11 #include "zcbor_encode.h"
12 #include "cbor/edhoc_encode_id_cred_x.h"
13 #include "zcbor_print.h"
14 
15 #if DEFAULT_MAX_QTY != 3
16 #error "The type file was generated with a different default_max_qty than this file"
17 #endif
18 
19 static bool encode_repeated_id_cred_x_map_kid(zcbor_state_t *state, const struct id_cred_x_map_kid_r *input);
20 static bool encode_repeated_id_cred_x_map_x5bag(zcbor_state_t *state, const struct id_cred_x_map_x5bag *input);
21 static bool encode_repeated_id_cred_x_map_x5chain(zcbor_state_t *state, const struct id_cred_x_map_x5chain *input);
22 static bool encode_repeated_id_cred_x_map_x5t(zcbor_state_t *state, const struct id_cred_x_map_x5t_r *input);
23 static bool encode_repeated_id_cred_x_map_x5u(zcbor_state_t *state, const struct id_cred_x_map_x5u *input);
24 static bool encode_repeated_id_cred_x_map_c5b(zcbor_state_t *state, const struct id_cred_x_map_c5b *input);
25 static bool encode_repeated_id_cred_x_map_c5c(zcbor_state_t *state, const struct id_cred_x_map_c5c *input);
26 static bool encode_repeated_id_cred_x_map_c5t(zcbor_state_t *state, const struct id_cred_x_map_c5t_r *input);
27 static bool encode_repeated_id_cred_x_map_c5u(zcbor_state_t *state, const struct id_cred_x_map_c5u *input);
28 static bool encode_id_cred_x_map(zcbor_state_t *state, const struct id_cred_x_map *input);
29 
30 
encode_repeated_id_cred_x_map_kid(zcbor_state_t * state,const struct id_cred_x_map_kid_r * input)31 static bool encode_repeated_id_cred_x_map_kid(
32 		zcbor_state_t *state, const struct id_cred_x_map_kid_r *input)
33 {
34 	zcbor_log("%s\r\n", __func__);
35 
36 	bool tmp_result = ((((zcbor_uint32_put(state, (4))))
37 	&& (((*input).id_cred_x_map_kid_choice == id_cred_x_map_kid_int_c) ? ((zcbor_int32_encode(state, (&(*input).id_cred_x_map_kid_int))))
38 	: (((*input).id_cred_x_map_kid_choice == id_cred_x_map_kid_bstr_c) ? ((zcbor_bstr_encode(state, (&(*input).id_cred_x_map_kid_bstr))))
39 	: false))));
40 
41 	if (!tmp_result) {
42 		zcbor_trace_file(state);
43 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
44 	} else {
45 		zcbor_log("%s success\r\n", __func__);
46 	}
47 
48 	return tmp_result;
49 }
50 
encode_repeated_id_cred_x_map_x5bag(zcbor_state_t * state,const struct id_cred_x_map_x5bag * input)51 static bool encode_repeated_id_cred_x_map_x5bag(
52 		zcbor_state_t *state, const struct id_cred_x_map_x5bag *input)
53 {
54 	zcbor_log("%s\r\n", __func__);
55 
56 	bool tmp_result = ((((zcbor_uint32_put(state, (32))))
57 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_x5bag)))));
58 
59 	if (!tmp_result) {
60 		zcbor_trace_file(state);
61 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
62 	} else {
63 		zcbor_log("%s success\r\n", __func__);
64 	}
65 
66 	return tmp_result;
67 }
68 
encode_repeated_id_cred_x_map_x5chain(zcbor_state_t * state,const struct id_cred_x_map_x5chain * input)69 static bool encode_repeated_id_cred_x_map_x5chain(
70 		zcbor_state_t *state, const struct id_cred_x_map_x5chain *input)
71 {
72 	zcbor_log("%s\r\n", __func__);
73 
74 	bool tmp_result = ((((zcbor_uint32_put(state, (33))))
75 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_x5chain)))));
76 
77 	if (!tmp_result) {
78 		zcbor_trace_file(state);
79 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
80 	} else {
81 		zcbor_log("%s success\r\n", __func__);
82 	}
83 
84 	return tmp_result;
85 }
86 
encode_repeated_id_cred_x_map_x5t(zcbor_state_t * state,const struct id_cred_x_map_x5t_r * input)87 static bool encode_repeated_id_cred_x_map_x5t(
88 		zcbor_state_t *state, const struct id_cred_x_map_x5t_r *input)
89 {
90 	zcbor_log("%s\r\n", __func__);
91 
92 	bool tmp_result = ((((zcbor_uint32_put(state, (34))))
93 	&& (zcbor_list_start_encode(state, 2) && ((((((*input).id_cred_x_map_x5t_alg_choice == id_cred_x_map_x5t_alg_int_c) ? ((zcbor_int32_encode(state, (&(*input).id_cred_x_map_x5t_alg_int))))
94 	: (((*input).id_cred_x_map_x5t_alg_choice == id_cred_x_map_x5t_alg_tstr_c) ? ((zcbor_tstr_encode(state, (&(*input).id_cred_x_map_x5t_alg_tstr))))
95 	: false)))
96 	&& ((zcbor_bstr_encode(state, (&(*input).id_cred_x_map_x5t_hash))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 2))));
97 
98 	if (!tmp_result) {
99 		zcbor_trace_file(state);
100 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
101 	} else {
102 		zcbor_log("%s success\r\n", __func__);
103 	}
104 
105 	return tmp_result;
106 }
107 
encode_repeated_id_cred_x_map_x5u(zcbor_state_t * state,const struct id_cred_x_map_x5u * input)108 static bool encode_repeated_id_cred_x_map_x5u(
109 		zcbor_state_t *state, const struct id_cred_x_map_x5u *input)
110 {
111 	zcbor_log("%s\r\n", __func__);
112 
113 	bool tmp_result = ((((zcbor_uint32_put(state, (35))))
114 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_x5u)))));
115 
116 	if (!tmp_result) {
117 		zcbor_trace_file(state);
118 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
119 	} else {
120 		zcbor_log("%s success\r\n", __func__);
121 	}
122 
123 	return tmp_result;
124 }
125 
encode_repeated_id_cred_x_map_c5b(zcbor_state_t * state,const struct id_cred_x_map_c5b * input)126 static bool encode_repeated_id_cred_x_map_c5b(
127 		zcbor_state_t *state, const struct id_cred_x_map_c5b *input)
128 {
129 	zcbor_log("%s\r\n", __func__);
130 
131 	bool tmp_result = ((((zcbor_uint32_put(state, (52))))
132 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_c5b)))));
133 
134 	if (!tmp_result) {
135 		zcbor_trace_file(state);
136 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
137 	} else {
138 		zcbor_log("%s success\r\n", __func__);
139 	}
140 
141 	return tmp_result;
142 }
143 
encode_repeated_id_cred_x_map_c5c(zcbor_state_t * state,const struct id_cred_x_map_c5c * input)144 static bool encode_repeated_id_cred_x_map_c5c(
145 		zcbor_state_t *state, const struct id_cred_x_map_c5c *input)
146 {
147 	zcbor_log("%s\r\n", __func__);
148 
149 	bool tmp_result = ((((zcbor_uint32_put(state, (53))))
150 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_c5c)))));
151 
152 	if (!tmp_result) {
153 		zcbor_trace_file(state);
154 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
155 	} else {
156 		zcbor_log("%s success\r\n", __func__);
157 	}
158 
159 	return tmp_result;
160 }
161 
encode_repeated_id_cred_x_map_c5t(zcbor_state_t * state,const struct id_cred_x_map_c5t_r * input)162 static bool encode_repeated_id_cred_x_map_c5t(
163 		zcbor_state_t *state, const struct id_cred_x_map_c5t_r *input)
164 {
165 	zcbor_log("%s\r\n", __func__);
166 
167 	bool tmp_result = ((((zcbor_uint32_put(state, (54))))
168 	&& (zcbor_list_start_encode(state, 2) && ((((((*input).id_cred_x_map_c5t_alg_choice == id_cred_x_map_c5t_alg_int_c) ? ((zcbor_int32_encode(state, (&(*input).id_cred_x_map_c5t_alg_int))))
169 	: (((*input).id_cred_x_map_c5t_alg_choice == id_cred_x_map_c5t_alg_tstr_c) ? ((zcbor_tstr_encode(state, (&(*input).id_cred_x_map_c5t_alg_tstr))))
170 	: false)))
171 	&& ((zcbor_bstr_encode(state, (&(*input).id_cred_x_map_c5t_hash))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 2))));
172 
173 	if (!tmp_result) {
174 		zcbor_trace_file(state);
175 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
176 	} else {
177 		zcbor_log("%s success\r\n", __func__);
178 	}
179 
180 	return tmp_result;
181 }
182 
encode_repeated_id_cred_x_map_c5u(zcbor_state_t * state,const struct id_cred_x_map_c5u * input)183 static bool encode_repeated_id_cred_x_map_c5u(
184 		zcbor_state_t *state, const struct id_cred_x_map_c5u *input)
185 {
186 	zcbor_log("%s\r\n", __func__);
187 
188 	bool tmp_result = ((((zcbor_uint32_put(state, (55))))
189 	&& (zcbor_bstr_encode(state, (&(*input).id_cred_x_map_c5u)))));
190 
191 	if (!tmp_result) {
192 		zcbor_trace_file(state);
193 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
194 	} else {
195 		zcbor_log("%s success\r\n", __func__);
196 	}
197 
198 	return tmp_result;
199 }
200 
encode_id_cred_x_map(zcbor_state_t * state,const struct id_cred_x_map * input)201 static bool encode_id_cred_x_map(
202 		zcbor_state_t *state, const struct id_cred_x_map *input)
203 {
204 	zcbor_log("%s\r\n", __func__);
205 
206 	bool tmp_result = (((zcbor_map_start_encode(state, 9) && (((!(*input).id_cred_x_map_kid_present || encode_repeated_id_cred_x_map_kid(state, (&(*input).id_cred_x_map_kid)))
207 	&& (!(*input).id_cred_x_map_x5bag_present || encode_repeated_id_cred_x_map_x5bag(state, (&(*input).id_cred_x_map_x5bag)))
208 	&& (!(*input).id_cred_x_map_x5chain_present || encode_repeated_id_cred_x_map_x5chain(state, (&(*input).id_cred_x_map_x5chain)))
209 	&& (!(*input).id_cred_x_map_x5t_present || encode_repeated_id_cred_x_map_x5t(state, (&(*input).id_cred_x_map_x5t)))
210 	&& (!(*input).id_cred_x_map_x5u_present || encode_repeated_id_cred_x_map_x5u(state, (&(*input).id_cred_x_map_x5u)))
211 	&& (!(*input).id_cred_x_map_c5b_present || encode_repeated_id_cred_x_map_c5b(state, (&(*input).id_cred_x_map_c5b)))
212 	&& (!(*input).id_cred_x_map_c5c_present || encode_repeated_id_cred_x_map_c5c(state, (&(*input).id_cred_x_map_c5c)))
213 	&& (!(*input).id_cred_x_map_c5t_present || encode_repeated_id_cred_x_map_c5t(state, (&(*input).id_cred_x_map_c5t)))
214 	&& (!(*input).id_cred_x_map_c5u_present || encode_repeated_id_cred_x_map_c5u(state, (&(*input).id_cred_x_map_c5u)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 9))));
215 
216 	if (!tmp_result) {
217 		zcbor_trace_file(state);
218 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
219 	} else {
220 		zcbor_log("%s success\r\n", __func__);
221 	}
222 
223 	return tmp_result;
224 }
225 
226 
227 
cbor_encode_id_cred_x_map(uint8_t * payload,size_t payload_len,const struct id_cred_x_map * input,size_t * payload_len_out)228 int cbor_encode_id_cred_x_map(
229 		uint8_t *payload, size_t payload_len,
230 		const struct id_cred_x_map *input,
231 		size_t *payload_len_out)
232 {
233 	zcbor_state_t states[5];
234 
235 	return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states,
236 		(zcbor_decoder_t *)encode_id_cred_x_map, sizeof(states) / sizeof(zcbor_state_t), 1);
237 }
238