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_aad_array.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_aad_array(zcbor_state_t * state,const struct aad_array * input)19 static bool encode_aad_array(
20 zcbor_state_t *state, const struct aad_array *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_uint32_encode(state, (&(*input)._aad_array_oscore_version))))
26 && ((zcbor_list_start_encode(state, 1) && (int_res = (((((*input)._aad_array_algorithms_alg_aead_choice == _aad_array_algorithms_alg_aead_int) ? ((zcbor_int32_encode(state, (&(*input)._aad_array_algorithms_alg_aead_int))))
27 : (((*input)._aad_array_algorithms_alg_aead_choice == _aad_array_algorithms_alg_aead_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._aad_array_algorithms_alg_aead_tstr))))
28 : false)))), ((zcbor_list_end_encode(state, 1)) && int_res))))
29 && ((zcbor_bstr_encode(state, (&(*input)._aad_array_request_kid))))
30 && ((zcbor_bstr_encode(state, (&(*input)._aad_array_request_piv))))
31 && ((zcbor_bstr_encode(state, (&(*input)._aad_array_options))))), ((zcbor_list_end_encode(state, 5)) && int_res)))));
32
33 if (!tmp_result)
34 zcbor_trace();
35
36 return tmp_result;
37 }
38
39
40
cbor_encode_aad_array(uint8_t * payload,size_t payload_len,const struct aad_array * input,size_t * payload_len_out)41 bool cbor_encode_aad_array(
42 uint8_t *payload, size_t payload_len,
43 const struct aad_array *input,
44 size_t *payload_len_out)
45 {
46 zcbor_state_t states[5];
47
48 zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
49
50 bool ret = encode_aad_array(states, input);
51
52 if (ret && (payload_len_out != NULL)) {
53 *payload_len_out = MIN(payload_len,
54 (size_t)states[0].payload - (size_t)payload);
55 }
56
57 return ret;
58 }
59