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/oscore_info.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_oscore_info(zcbor_state_t * state,const struct oscore_info * input)19 static bool encode_oscore_info(
20 		zcbor_state_t *state, const struct oscore_info *input)
21 {
22 	zcbor_print("%s\r\n", __func__);
23 	bool int_res;
24 
25 	bool tmp_result = (((zcbor_list_start_encode(state, 5) && (int_res = (((zcbor_bstr_encode(state, (&(*input)._oscore_info_id))))
26 	&& ((((*input)._oscore_info_id_context_choice == _oscore_info_id_context_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._oscore_info_id_context_bstr))))
27 	: (((*input)._oscore_info_id_context_choice == _oscore_info_id_context_nil) ? ((zcbor_nil_put(state, NULL)))
28 	: false)))
29 	&& ((((*input)._oscore_info_alg_aead_choice == _oscore_info_alg_aead_int) ? ((zcbor_int32_encode(state, (&(*input)._oscore_info_alg_aead_int))))
30 	: (((*input)._oscore_info_alg_aead_choice == _oscore_info_alg_aead_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._oscore_info_alg_aead_tstr))))
31 	: false)))
32 	&& ((zcbor_tstr_encode(state, (&(*input)._oscore_info_type))))
33 	&& ((zcbor_uint32_encode(state, (&(*input)._oscore_info_L))))), ((zcbor_list_end_encode(state, 5)) && int_res)))));
34 
35 	if (!tmp_result)
36 		zcbor_trace();
37 
38 	return tmp_result;
39 }
40 
41 
42 
cbor_encode_oscore_info(uint8_t * payload,size_t payload_len,const struct oscore_info * input,size_t * payload_len_out)43 bool cbor_encode_oscore_info(
44 		uint8_t *payload, size_t payload_len,
45 		const struct oscore_info *input,
46 		size_t *payload_len_out)
47 {
48 	zcbor_state_t states[4];
49 
50 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
51 
52 	bool ret = encode_oscore_info(states, input);
53 
54 	if (ret && (payload_len_out != NULL)) {
55 		*payload_len_out = MIN(payload_len,
56 				(size_t)states[0].payload - (size_t)payload);
57 	}
58 
59 	return ret;
60 }
61