1 /* 2 * Copyright (c) 2022 Eriptic Technologies. 3 * 4 * SPDX-License-Identifier: Apache-2.0 or MIT 5 */ 6 7 #ifndef INT_ENCODE_DECODE_H 8 #define INT_ENCODE_DECODE_H 9 10 #include <stdint.h> 11 #include "common/oscore_edhoc_error.h" 12 13 /** 14 * @brief Decodes an int from CBOR. 15 * 16 * @param[in] in The input CBOR data. 17 * @param[out] out The result. 18 * @return Ok or error code. 19 */ 20 enum err decode_int(const struct byte_array *in, int32_t *out); 21 22 /** 23 * @brief Encodes an int in CBOR. 24 * 25 * @param[in] in The input int. 26 * @param in_len The length of the int. 27 * @param[out] out The result. 28 * @return Ok or error code. 29 */ 30 enum err encode_int(const int32_t *in, uint32_t in_len, struct byte_array *out); 31 32 /** 33 * @brief Checks if the C_I chosen by the user is actually 34 * an encoding for a CBOR int in the range -24..23 35 * or another byte string that needs to be encoded 36 * as CBOR bstr in message 1. 37 * 38 * @param c_i Connection identifier of the initiator 39 * @return true if it as int representation 40 * @return false if it is a raw byte string 41 */ 42 bool c_x_is_encoded_int(const struct byte_array *c_i); 43 44 /** 45 * @brief Checks if C_R is raw int or a raw byte string 46 * 47 * @param c_r Connection identifier of the responder 48 * @return true if it is a raw int 49 * @return false if it is a raw byte string 50 */ 51 bool c_r_is_raw_int(const struct byte_array *c_r); 52 53 #endif