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