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_message_2.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_m2(zcbor_state_t * state,struct m2 * result)19 static bool decode_m2(
20 		zcbor_state_t *state, struct m2 *result)
21 {
22 	zcbor_print("%s\r\n", __func__);
23 	bool int_res;
24 
25 	bool tmp_result = (((((zcbor_bstr_decode(state, (&(*result)._m2_G_Y_CIPHERTEXT_2))))
26 	&& ((zcbor_union_start_code(state) && (int_res = ((((zcbor_int32_decode(state, (&(*result)._m2_C_R_int)))) && (((*result)._m2_C_R_choice = _m2_C_R_int) || 1))
27 	|| (((zcbor_bstr_decode(state, (&(*result)._m2_C_R_bstr)))) && (((*result)._m2_C_R_choice = _m2_C_R_bstr) || 1))), zcbor_union_end_code(state), int_res))))));
28 
29 	if (!tmp_result)
30 		zcbor_trace();
31 
32 	return tmp_result;
33 }
34 
35 
36 
cbor_decode_m2(const uint8_t * payload,size_t payload_len,struct m2 * result,size_t * payload_len_out)37 bool cbor_decode_m2(
38 		const uint8_t *payload, size_t payload_len,
39 		struct m2 *result,
40 		size_t *payload_len_out)
41 {
42 	zcbor_state_t states[3];
43 
44 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 2);
45 
46 	bool ret = decode_m2(states, result);
47 
48 	if (ret && (payload_len_out != NULL)) {
49 		*payload_len_out = MIN(payload_len,
50 				(size_t)states[0].payload - (size_t)payload);
51 	}
52 
53 	return ret;
54 }
55