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_encode.h"
12 #include "cbor/edhoc_encode_id_cred_x.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 
encode_repeated_id_cred_x_map_kid(zcbor_state_t * state,const struct id_cred_x_map_kid * input)19 static bool encode_repeated_id_cred_x_map_kid(
20 		zcbor_state_t *state, const struct id_cred_x_map_kid *input)
21 {
22 	zcbor_print("%s\r\n", __func__);
23 
24 	bool tmp_result = ((((zcbor_uint32_put(state, (4))))
25 	&& (zcbor_int32_encode(state, (&(*input)._id_cred_x_map_kid)))));
26 
27 	if (!tmp_result)
28 		zcbor_trace();
29 
30 	return tmp_result;
31 }
32 
encode_repeated_id_cred_x_map_x5bag(zcbor_state_t * state,const struct id_cred_x_map_x5bag * input)33 static bool encode_repeated_id_cred_x_map_x5bag(
34 		zcbor_state_t *state, const struct id_cred_x_map_x5bag *input)
35 {
36 	zcbor_print("%s\r\n", __func__);
37 
38 	bool tmp_result = ((((zcbor_uint32_put(state, (32))))
39 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_x5bag)))));
40 
41 	if (!tmp_result)
42 		zcbor_trace();
43 
44 	return tmp_result;
45 }
46 
encode_repeated_id_cred_x_map_x5chain(zcbor_state_t * state,const struct id_cred_x_map_x5chain * input)47 static bool encode_repeated_id_cred_x_map_x5chain(
48 		zcbor_state_t *state, const struct id_cred_x_map_x5chain *input)
49 {
50 	zcbor_print("%s\r\n", __func__);
51 
52 	bool tmp_result = ((((zcbor_uint32_put(state, (33))))
53 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_x5chain)))));
54 
55 	if (!tmp_result)
56 		zcbor_trace();
57 
58 	return tmp_result;
59 }
60 
encode_repeated_id_cred_x_map_x5t(zcbor_state_t * state,const struct id_cred_x_map_x5t_ * input)61 static bool encode_repeated_id_cred_x_map_x5t(
62 		zcbor_state_t *state, const struct id_cred_x_map_x5t_ *input)
63 {
64 	zcbor_print("%s\r\n", __func__);
65 	bool int_res;
66 
67 	bool tmp_result = ((((zcbor_uint32_put(state, (34))))
68 	&& (zcbor_list_start_encode(state, 2) && (int_res = (((((*input)._id_cred_x_map_x5t_alg_choice == _id_cred_x_map_x5t_alg_int) ? ((zcbor_int32_encode(state, (&(*input)._id_cred_x_map_x5t_alg_int))))
69 	: (((*input)._id_cred_x_map_x5t_alg_choice == _id_cred_x_map_x5t_alg_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._id_cred_x_map_x5t_alg_tstr))))
70 	: false)))
71 	&& ((zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_x5t_hash))))), ((zcbor_list_end_encode(state, 2)) && int_res)))));
72 
73 	if (!tmp_result)
74 		zcbor_trace();
75 
76 	return tmp_result;
77 }
78 
encode_repeated_id_cred_x_map_x5u(zcbor_state_t * state,const struct id_cred_x_map_x5u * input)79 static bool encode_repeated_id_cred_x_map_x5u(
80 		zcbor_state_t *state, const struct id_cred_x_map_x5u *input)
81 {
82 	zcbor_print("%s\r\n", __func__);
83 
84 	bool tmp_result = ((((zcbor_uint32_put(state, (35))))
85 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_x5u)))));
86 
87 	if (!tmp_result)
88 		zcbor_trace();
89 
90 	return tmp_result;
91 }
92 
encode_repeated_id_cred_x_map_c5b(zcbor_state_t * state,const struct id_cred_x_map_c5b * input)93 static bool encode_repeated_id_cred_x_map_c5b(
94 		zcbor_state_t *state, const struct id_cred_x_map_c5b *input)
95 {
96 	zcbor_print("%s\r\n", __func__);
97 
98 	bool tmp_result = ((((zcbor_uint32_put(state, (52))))
99 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_c5b)))));
100 
101 	if (!tmp_result)
102 		zcbor_trace();
103 
104 	return tmp_result;
105 }
106 
encode_repeated_id_cred_x_map_c5c(zcbor_state_t * state,const struct id_cred_x_map_c5c * input)107 static bool encode_repeated_id_cred_x_map_c5c(
108 		zcbor_state_t *state, const struct id_cred_x_map_c5c *input)
109 {
110 	zcbor_print("%s\r\n", __func__);
111 
112 	bool tmp_result = ((((zcbor_uint32_put(state, (53))))
113 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_c5c)))));
114 
115 	if (!tmp_result)
116 		zcbor_trace();
117 
118 	return tmp_result;
119 }
120 
encode_repeated_id_cred_x_map_c5t(zcbor_state_t * state,const struct id_cred_x_map_c5t_ * input)121 static bool encode_repeated_id_cred_x_map_c5t(
122 		zcbor_state_t *state, const struct id_cred_x_map_c5t_ *input)
123 {
124 	zcbor_print("%s\r\n", __func__);
125 	bool int_res;
126 
127 	bool tmp_result = ((((zcbor_uint32_put(state, (54))))
128 	&& (zcbor_list_start_encode(state, 2) && (int_res = (((((*input)._id_cred_x_map_c5t_alg_choice == _id_cred_x_map_c5t_alg_int) ? ((zcbor_int32_encode(state, (&(*input)._id_cred_x_map_c5t_alg_int))))
129 	: (((*input)._id_cred_x_map_c5t_alg_choice == _id_cred_x_map_c5t_alg_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._id_cred_x_map_c5t_alg_tstr))))
130 	: false)))
131 	&& ((zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_c5t_hash))))), ((zcbor_list_end_encode(state, 2)) && int_res)))));
132 
133 	if (!tmp_result)
134 		zcbor_trace();
135 
136 	return tmp_result;
137 }
138 
encode_repeated_id_cred_x_map_c5u(zcbor_state_t * state,const struct id_cred_x_map_c5u * input)139 static bool encode_repeated_id_cred_x_map_c5u(
140 		zcbor_state_t *state, const struct id_cred_x_map_c5u *input)
141 {
142 	zcbor_print("%s\r\n", __func__);
143 
144 	bool tmp_result = ((((zcbor_uint32_put(state, (55))))
145 	&& (zcbor_bstr_encode(state, (&(*input)._id_cred_x_map_c5u)))));
146 
147 	if (!tmp_result)
148 		zcbor_trace();
149 
150 	return tmp_result;
151 }
152 
encode_id_cred_x_map(zcbor_state_t * state,const struct id_cred_x_map * input)153 static bool encode_id_cred_x_map(
154 		zcbor_state_t *state, const struct id_cred_x_map *input)
155 {
156 	zcbor_print("%s\r\n", __func__);
157 	bool int_res;
158 
159 	bool tmp_result = (((zcbor_map_start_encode(state, 9) && (int_res = (zcbor_present_encode(&((*input)._id_cred_x_map_kid_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_kid, state, (&(*input)._id_cred_x_map_kid))
160 	&& zcbor_present_encode(&((*input)._id_cred_x_map_x5bag_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_x5bag, state, (&(*input)._id_cred_x_map_x5bag))
161 	&& zcbor_present_encode(&((*input)._id_cred_x_map_x5chain_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_x5chain, state, (&(*input)._id_cred_x_map_x5chain))
162 	&& zcbor_present_encode(&((*input)._id_cred_x_map_x5t_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_x5t, state, (&(*input)._id_cred_x_map_x5t))
163 	&& zcbor_present_encode(&((*input)._id_cred_x_map_x5u_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_x5u, state, (&(*input)._id_cred_x_map_x5u))
164 	&& zcbor_present_encode(&((*input)._id_cred_x_map_c5b_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_c5b, state, (&(*input)._id_cred_x_map_c5b))
165 	&& zcbor_present_encode(&((*input)._id_cred_x_map_c5c_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_c5c, state, (&(*input)._id_cred_x_map_c5c))
166 	&& zcbor_present_encode(&((*input)._id_cred_x_map_c5t_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_c5t, state, (&(*input)._id_cred_x_map_c5t))
167 	&& zcbor_present_encode(&((*input)._id_cred_x_map_c5u_present), (zcbor_encoder_t *)encode_repeated_id_cred_x_map_c5u, state, (&(*input)._id_cred_x_map_c5u))), ((zcbor_map_end_encode(state, 9)) && int_res)))));
168 
169 	if (!tmp_result)
170 		zcbor_trace();
171 
172 	return tmp_result;
173 }
174 
175 
176 
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)177 bool cbor_encode_id_cred_x_map(
178 		uint8_t *payload, size_t payload_len,
179 		const struct id_cred_x_map *input,
180 		size_t *payload_len_out)
181 {
182 	zcbor_state_t states[5];
183 
184 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
185 
186 	bool ret = encode_id_cred_x_map(states, input);
187 
188 	if (ret && (payload_len_out != NULL)) {
189 		*payload_len_out = MIN(payload_len,
190 				(size_t)states[0].payload - (size_t)payload);
191 	}
192 
193 	return ret;
194 }
195