1 /*
2 * Generated using zcbor version 0.3.99
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
14 #if DEFAULT_MAX_QTY != 3
15 #error "The type file was generated with a different default_max_qty than this file"
16 #endif
17
18
decode_repeated_map_kid(zcbor_state_t * state,struct map_kid_ * result)19 static bool decode_repeated_map_kid(
20 zcbor_state_t *state, struct map_kid_ *result)
21 {
22 zcbor_print("%s\r\n", __func__);
23 bool int_res;
24
25 bool tmp_result = ((((zcbor_uint32_expect(state, (4))))
26 && (zcbor_union_start_code(state) && (int_res = ((((zcbor_int32_decode(state, (&(*result)._map_kid_int)))) && (((*result)._map_kid_choice = _map_kid_int) || 1))
27 || (((zcbor_bstr_decode(state, (&(*result)._map_kid_bstr)))) && (((*result)._map_kid_choice = _map_kid_bstr) || 1))), zcbor_union_end_code(state), int_res))));
28
29 if (!tmp_result)
30 zcbor_trace();
31
32 return tmp_result;
33 }
34
decode_repeated_map_x5bag(zcbor_state_t * state,struct map_x5bag * result)35 static bool decode_repeated_map_x5bag(
36 zcbor_state_t *state, struct map_x5bag *result)
37 {
38 zcbor_print("%s\r\n", __func__);
39
40 bool tmp_result = ((((zcbor_uint32_expect(state, (32))))
41 && (zcbor_bstr_decode(state, (&(*result)._map_x5bag)))));
42
43 if (!tmp_result)
44 zcbor_trace();
45
46 return tmp_result;
47 }
48
decode_repeated_map_x5chain(zcbor_state_t * state,struct map_x5chain * result)49 static bool decode_repeated_map_x5chain(
50 zcbor_state_t *state, struct map_x5chain *result)
51 {
52 zcbor_print("%s\r\n", __func__);
53
54 bool tmp_result = ((((zcbor_uint32_expect(state, (33))))
55 && (zcbor_bstr_decode(state, (&(*result)._map_x5chain)))));
56
57 if (!tmp_result)
58 zcbor_trace();
59
60 return tmp_result;
61 }
62
decode_repeated_map_x5t(zcbor_state_t * state,struct map_x5t_ * result)63 static bool decode_repeated_map_x5t(
64 zcbor_state_t *state, struct map_x5t_ *result)
65 {
66 zcbor_print("%s\r\n", __func__);
67 bool int_res;
68
69 bool tmp_result = ((((zcbor_uint32_expect(state, (34))))
70 && (zcbor_list_start_decode(state) && (int_res = (((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) || 1))
71 || (((zcbor_tstr_decode(state, (&(*result)._map_x5t_alg_tstr)))) && (((*result)._map_x5t_alg_choice = _map_x5t_alg_tstr) || 1))), zcbor_union_end_code(state), int_res)))
72 && ((zcbor_bstr_decode(state, (&(*result)._map_x5t_hash))))), ((zcbor_list_end_decode(state)) && int_res)))));
73
74 if (!tmp_result)
75 zcbor_trace();
76
77 return tmp_result;
78 }
79
decode_repeated_map_x5u(zcbor_state_t * state,struct map_x5u * result)80 static bool decode_repeated_map_x5u(
81 zcbor_state_t *state, struct map_x5u *result)
82 {
83 zcbor_print("%s\r\n", __func__);
84
85 bool tmp_result = ((((zcbor_uint32_expect(state, (35))))
86 && (zcbor_bstr_decode(state, (&(*result)._map_x5u)))));
87
88 if (!tmp_result)
89 zcbor_trace();
90
91 return tmp_result;
92 }
93
decode_repeated_map_c5b(zcbor_state_t * state,struct map_c5b * result)94 static bool decode_repeated_map_c5b(
95 zcbor_state_t *state, struct map_c5b *result)
96 {
97 zcbor_print("%s\r\n", __func__);
98
99 bool tmp_result = ((((zcbor_uint32_expect(state, (52))))
100 && (zcbor_bstr_decode(state, (&(*result)._map_c5b)))));
101
102 if (!tmp_result)
103 zcbor_trace();
104
105 return tmp_result;
106 }
107
decode_repeated_map_c5c(zcbor_state_t * state,struct map_c5c * result)108 static bool decode_repeated_map_c5c(
109 zcbor_state_t *state, struct map_c5c *result)
110 {
111 zcbor_print("%s\r\n", __func__);
112
113 bool tmp_result = ((((zcbor_uint32_expect(state, (53))))
114 && (zcbor_bstr_decode(state, (&(*result)._map_c5c)))));
115
116 if (!tmp_result)
117 zcbor_trace();
118
119 return tmp_result;
120 }
121
decode_repeated_map_c5t(zcbor_state_t * state,struct map_c5t_ * result)122 static bool decode_repeated_map_c5t(
123 zcbor_state_t *state, struct map_c5t_ *result)
124 {
125 zcbor_print("%s\r\n", __func__);
126 bool int_res;
127
128 bool tmp_result = ((((zcbor_uint32_expect(state, (54))))
129 && (zcbor_list_start_decode(state) && (int_res = (((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) || 1))
130 || (((zcbor_tstr_decode(state, (&(*result)._map_c5t_alg_tstr)))) && (((*result)._map_c5t_alg_choice = _map_c5t_alg_tstr) || 1))), zcbor_union_end_code(state), int_res)))
131 && ((zcbor_bstr_decode(state, (&(*result)._map_c5t_hash))))), ((zcbor_list_end_decode(state)) && int_res)))));
132
133 if (!tmp_result)
134 zcbor_trace();
135
136 return tmp_result;
137 }
138
decode_repeated_map_c5u(zcbor_state_t * state,struct map_c5u * result)139 static bool decode_repeated_map_c5u(
140 zcbor_state_t *state, struct map_c5u *result)
141 {
142 zcbor_print("%s\r\n", __func__);
143
144 bool tmp_result = ((((zcbor_uint32_expect(state, (55))))
145 && (zcbor_bstr_decode(state, (&(*result)._map_c5u)))));
146
147 if (!tmp_result)
148 zcbor_trace();
149
150 return tmp_result;
151 }
152
decode_map(zcbor_state_t * state,struct map * result)153 static bool decode_map(
154 zcbor_state_t *state, struct map *result)
155 {
156 zcbor_print("%s\r\n", __func__);
157 bool int_res;
158
159 bool tmp_result = (((zcbor_map_start_decode(state) && (int_res = (zcbor_present_decode(&((*result)._map_kid_present), (zcbor_decoder_t *)decode_repeated_map_kid, state, (&(*result)._map_kid))
160 && zcbor_present_decode(&((*result)._map_x5bag_present), (zcbor_decoder_t *)decode_repeated_map_x5bag, state, (&(*result)._map_x5bag))
161 && zcbor_present_decode(&((*result)._map_x5chain_present), (zcbor_decoder_t *)decode_repeated_map_x5chain, state, (&(*result)._map_x5chain))
162 && zcbor_present_decode(&((*result)._map_x5t_present), (zcbor_decoder_t *)decode_repeated_map_x5t, state, (&(*result)._map_x5t))
163 && zcbor_present_decode(&((*result)._map_x5u_present), (zcbor_decoder_t *)decode_repeated_map_x5u, state, (&(*result)._map_x5u))
164 && zcbor_present_decode(&((*result)._map_c5b_present), (zcbor_decoder_t *)decode_repeated_map_c5b, state, (&(*result)._map_c5b))
165 && zcbor_present_decode(&((*result)._map_c5c_present), (zcbor_decoder_t *)decode_repeated_map_c5c, state, (&(*result)._map_c5c))
166 && zcbor_present_decode(&((*result)._map_c5t_present), (zcbor_decoder_t *)decode_repeated_map_c5t, state, (&(*result)._map_c5t))
167 && zcbor_present_decode(&((*result)._map_c5u_present), (zcbor_decoder_t *)decode_repeated_map_c5u, state, (&(*result)._map_c5u))), ((zcbor_map_end_decode(state)) && int_res)))));
168
169 if (!tmp_result)
170 zcbor_trace();
171
172 return tmp_result;
173 }
174
decode_plaintext(zcbor_state_t * state,struct plaintext * result)175 static bool decode_plaintext(
176 zcbor_state_t *state, struct plaintext *result)
177 {
178 zcbor_print("%s\r\n", __func__);
179 bool int_res;
180
181 bool tmp_result = (((((zcbor_union_start_code(state) && (int_res = ((((decode_map(state, (&(*result)._plaintext_ID_CRED_x__map)))) && (((*result)._plaintext_ID_CRED_x_choice = _plaintext_ID_CRED_x__map) || 1))
182 || (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) || 1)))
183 || (((zcbor_int32_decode(state, (&(*result)._plaintext_ID_CRED_x_int)))) && (((*result)._plaintext_ID_CRED_x_choice = _plaintext_ID_CRED_x_int) || 1))), zcbor_union_end_code(state), int_res)))
184 && ((zcbor_bstr_decode(state, (&(*result)._plaintext_SGN_or_MAC_x))))
185 && zcbor_present_decode(&((*result)._plaintext_AD_x_present), (zcbor_decoder_t *)zcbor_bstr_decode, state, (&(*result)._plaintext_AD_x)))));
186
187 if (!tmp_result)
188 zcbor_trace();
189
190 return tmp_result;
191 }
192
193
194
cbor_decode_plaintext(const uint8_t * payload,size_t payload_len,struct plaintext * result,size_t * payload_len_out)195 bool cbor_decode_plaintext(
196 const uint8_t *payload, size_t payload_len,
197 struct plaintext *result,
198 size_t *payload_len_out)
199 {
200 zcbor_state_t states[6];
201
202 zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 3);
203
204 bool ret = decode_plaintext(states, result);
205
206 if (ret && (payload_len_out != NULL)) {
207 *payload_len_out = MIN(payload_len,
208 (size_t)states[0].payload - (size_t)payload);
209 }
210
211 return ret;
212 }
213