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_decode.h"
12 #include "cbor/edhoc_decode_plaintext.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 decode_repeated_map_kid(zcbor_state_t *state, struct map_kid_r *result);
20 static bool decode_repeated_map_x5bag(zcbor_state_t *state, struct map_x5bag *result);
21 static bool decode_repeated_map_x5chain(zcbor_state_t *state, struct map_x5chain *result);
22 static bool decode_repeated_map_x5t(zcbor_state_t *state, struct map_x5t_r *result);
23 static bool decode_repeated_map_x5u(zcbor_state_t *state, struct map_x5u *result);
24 static bool decode_repeated_map_c5b(zcbor_state_t *state, struct map_c5b *result);
25 static bool decode_repeated_map_c5c(zcbor_state_t *state, struct map_c5c *result);
26 static bool decode_repeated_map_c5t(zcbor_state_t *state, struct map_c5t_r *result);
27 static bool decode_repeated_map_c5u(zcbor_state_t *state, struct map_c5u *result);
28 static bool decode_map(zcbor_state_t *state, struct map *result);
29 static bool decode_plaintext(zcbor_state_t *state, struct plaintext *result);
30
31
decode_repeated_map_kid(zcbor_state_t * state,struct map_kid_r * result)32 static bool decode_repeated_map_kid(
33 zcbor_state_t *state, struct map_kid_r *result)
34 {
35 zcbor_log("%s\r\n", __func__);
36 bool int_res;
37
38 bool tmp_result = ((((zcbor_uint32_expect(state, (4))))
39 && (zcbor_union_start_code(state) && (int_res = ((((zcbor_int32_decode(state, (&(*result).map_kid_int)))) && (((*result).map_kid_choice = map_kid_int_c), true))
40 || (((zcbor_bstr_decode(state, (&(*result).map_kid_bstr)))) && (((*result).map_kid_choice = map_kid_bstr_c), true))), zcbor_union_end_code(state), int_res))));
41
42 if (!tmp_result) {
43 zcbor_trace_file(state);
44 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
45 } else {
46 zcbor_log("%s success\r\n", __func__);
47 }
48
49 return tmp_result;
50 }
51
decode_repeated_map_x5bag(zcbor_state_t * state,struct map_x5bag * result)52 static bool decode_repeated_map_x5bag(
53 zcbor_state_t *state, struct map_x5bag *result)
54 {
55 zcbor_log("%s\r\n", __func__);
56
57 bool tmp_result = ((((zcbor_uint32_expect(state, (32))))
58 && (zcbor_bstr_decode(state, (&(*result).map_x5bag)))));
59
60 if (!tmp_result) {
61 zcbor_trace_file(state);
62 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
63 } else {
64 zcbor_log("%s success\r\n", __func__);
65 }
66
67 return tmp_result;
68 }
69
decode_repeated_map_x5chain(zcbor_state_t * state,struct map_x5chain * result)70 static bool decode_repeated_map_x5chain(
71 zcbor_state_t *state, struct map_x5chain *result)
72 {
73 zcbor_log("%s\r\n", __func__);
74
75 bool tmp_result = ((((zcbor_uint32_expect(state, (33))))
76 && (zcbor_bstr_decode(state, (&(*result).map_x5chain)))));
77
78 if (!tmp_result) {
79 zcbor_trace_file(state);
80 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
81 } else {
82 zcbor_log("%s success\r\n", __func__);
83 }
84
85 return tmp_result;
86 }
87
decode_repeated_map_x5t(zcbor_state_t * state,struct map_x5t_r * result)88 static bool decode_repeated_map_x5t(
89 zcbor_state_t *state, struct map_x5t_r *result)
90 {
91 zcbor_log("%s\r\n", __func__);
92 bool int_res;
93
94 bool tmp_result = ((((zcbor_uint32_expect(state, (34))))
95 && (zcbor_list_start_decode(state) && ((((zcbor_union_start_code(state) && (int_res = ((((zcbor_int32_decode(state, (&(*result).map_x5t_alg_int)))) && (((*result).map_x5t_alg_choice = map_x5t_alg_int_c), true))
96 || (((zcbor_tstr_decode(state, (&(*result).map_x5t_alg_tstr)))) && (((*result).map_x5t_alg_choice = map_x5t_alg_tstr_c), true))), zcbor_union_end_code(state), int_res)))
97 && ((zcbor_bstr_decode(state, (&(*result).map_x5t_hash))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
98
99 if (!tmp_result) {
100 zcbor_trace_file(state);
101 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
102 } else {
103 zcbor_log("%s success\r\n", __func__);
104 }
105
106 return tmp_result;
107 }
108
decode_repeated_map_x5u(zcbor_state_t * state,struct map_x5u * result)109 static bool decode_repeated_map_x5u(
110 zcbor_state_t *state, struct map_x5u *result)
111 {
112 zcbor_log("%s\r\n", __func__);
113
114 bool tmp_result = ((((zcbor_uint32_expect(state, (35))))
115 && (zcbor_bstr_decode(state, (&(*result).map_x5u)))));
116
117 if (!tmp_result) {
118 zcbor_trace_file(state);
119 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
120 } else {
121 zcbor_log("%s success\r\n", __func__);
122 }
123
124 return tmp_result;
125 }
126
decode_repeated_map_c5b(zcbor_state_t * state,struct map_c5b * result)127 static bool decode_repeated_map_c5b(
128 zcbor_state_t *state, struct map_c5b *result)
129 {
130 zcbor_log("%s\r\n", __func__);
131
132 bool tmp_result = ((((zcbor_uint32_expect(state, (52))))
133 && (zcbor_bstr_decode(state, (&(*result).map_c5b)))));
134
135 if (!tmp_result) {
136 zcbor_trace_file(state);
137 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
138 } else {
139 zcbor_log("%s success\r\n", __func__);
140 }
141
142 return tmp_result;
143 }
144
decode_repeated_map_c5c(zcbor_state_t * state,struct map_c5c * result)145 static bool decode_repeated_map_c5c(
146 zcbor_state_t *state, struct map_c5c *result)
147 {
148 zcbor_log("%s\r\n", __func__);
149
150 bool tmp_result = ((((zcbor_uint32_expect(state, (53))))
151 && (zcbor_bstr_decode(state, (&(*result).map_c5c)))));
152
153 if (!tmp_result) {
154 zcbor_trace_file(state);
155 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
156 } else {
157 zcbor_log("%s success\r\n", __func__);
158 }
159
160 return tmp_result;
161 }
162
decode_repeated_map_c5t(zcbor_state_t * state,struct map_c5t_r * result)163 static bool decode_repeated_map_c5t(
164 zcbor_state_t *state, struct map_c5t_r *result)
165 {
166 zcbor_log("%s\r\n", __func__);
167 bool int_res;
168
169 bool tmp_result = ((((zcbor_uint32_expect(state, (54))))
170 && (zcbor_list_start_decode(state) && ((((zcbor_union_start_code(state) && (int_res = ((((zcbor_int32_decode(state, (&(*result).map_c5t_alg_int)))) && (((*result).map_c5t_alg_choice = map_c5t_alg_int_c), true))
171 || (((zcbor_tstr_decode(state, (&(*result).map_c5t_alg_tstr)))) && (((*result).map_c5t_alg_choice = map_c5t_alg_tstr_c), true))), zcbor_union_end_code(state), int_res)))
172 && ((zcbor_bstr_decode(state, (&(*result).map_c5t_hash))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
173
174 if (!tmp_result) {
175 zcbor_trace_file(state);
176 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
177 } else {
178 zcbor_log("%s success\r\n", __func__);
179 }
180
181 return tmp_result;
182 }
183
decode_repeated_map_c5u(zcbor_state_t * state,struct map_c5u * result)184 static bool decode_repeated_map_c5u(
185 zcbor_state_t *state, struct map_c5u *result)
186 {
187 zcbor_log("%s\r\n", __func__);
188
189 bool tmp_result = ((((zcbor_uint32_expect(state, (55))))
190 && (zcbor_bstr_decode(state, (&(*result).map_c5u)))));
191
192 if (!tmp_result) {
193 zcbor_trace_file(state);
194 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
195 } else {
196 zcbor_log("%s success\r\n", __func__);
197 }
198
199 return tmp_result;
200 }
201
decode_map(zcbor_state_t * state,struct map * result)202 static bool decode_map(
203 zcbor_state_t *state, struct map *result)
204 {
205 zcbor_log("%s\r\n", __func__);
206
207 bool tmp_result = (((zcbor_map_start_decode(state) && ((zcbor_present_decode(&((*result).map_kid_present), (zcbor_decoder_t *)decode_repeated_map_kid, state, (&(*result).map_kid))
208 && zcbor_present_decode(&((*result).map_x5bag_present), (zcbor_decoder_t *)decode_repeated_map_x5bag, state, (&(*result).map_x5bag))
209 && zcbor_present_decode(&((*result).map_x5chain_present), (zcbor_decoder_t *)decode_repeated_map_x5chain, state, (&(*result).map_x5chain))
210 && zcbor_present_decode(&((*result).map_x5t_present), (zcbor_decoder_t *)decode_repeated_map_x5t, state, (&(*result).map_x5t))
211 && zcbor_present_decode(&((*result).map_x5u_present), (zcbor_decoder_t *)decode_repeated_map_x5u, state, (&(*result).map_x5u))
212 && zcbor_present_decode(&((*result).map_c5b_present), (zcbor_decoder_t *)decode_repeated_map_c5b, state, (&(*result).map_c5b))
213 && zcbor_present_decode(&((*result).map_c5c_present), (zcbor_decoder_t *)decode_repeated_map_c5c, state, (&(*result).map_c5c))
214 && zcbor_present_decode(&((*result).map_c5t_present), (zcbor_decoder_t *)decode_repeated_map_c5t, state, (&(*result).map_c5t))
215 && zcbor_present_decode(&((*result).map_c5u_present), (zcbor_decoder_t *)decode_repeated_map_c5u, state, (&(*result).map_c5u))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state))));
216
217 if (!tmp_result) {
218 zcbor_trace_file(state);
219 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
220 } else {
221 zcbor_log("%s success\r\n", __func__);
222 }
223
224 return tmp_result;
225 }
226
decode_plaintext(zcbor_state_t * state,struct plaintext * result)227 static bool decode_plaintext(
228 zcbor_state_t *state, struct plaintext *result)
229 {
230 zcbor_log("%s\r\n", __func__);
231 bool int_res;
232
233 bool tmp_result = (((((zcbor_union_start_code(state) && (int_res = ((((decode_map(state, (&(*result).plaintext_ID_CRED_x_map_m)))) && (((*result).plaintext_ID_CRED_x_choice = plaintext_ID_CRED_x_map_m_c), true))
234 || (zcbor_union_elem_code(state) && (((zcbor_bstr_decode(state, (&(*result).plaintext_ID_CRED_x_bstr)))) && (((*result).plaintext_ID_CRED_x_choice = plaintext_ID_CRED_x_bstr_c), true)))
235 || (((zcbor_int32_decode(state, (&(*result).plaintext_ID_CRED_x_int)))) && (((*result).plaintext_ID_CRED_x_choice = plaintext_ID_CRED_x_int_c), true))), zcbor_union_end_code(state), int_res)))
236 && ((zcbor_bstr_decode(state, (&(*result).plaintext_SGN_or_MAC_x))))
237 && ((*result).plaintext_AD_x_present = ((zcbor_bstr_decode(state, (&(*result).plaintext_AD_x)))), 1))));
238
239 if (!tmp_result) {
240 zcbor_trace_file(state);
241 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
242 } else {
243 zcbor_log("%s success\r\n", __func__);
244 }
245
246 return tmp_result;
247 }
248
249
250
cbor_decode_plaintext(const uint8_t * payload,size_t payload_len,struct plaintext * result,size_t * payload_len_out)251 int cbor_decode_plaintext(
252 const uint8_t *payload, size_t payload_len,
253 struct plaintext *result,
254 size_t *payload_len_out)
255 {
256 zcbor_state_t states[6];
257
258 return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
259 (zcbor_decoder_t *)decode_plaintext, sizeof(states) / sizeof(zcbor_state_t), 3);
260 }
261