1 /*
2  * Copyright (c) 2022 Eriptic Technologies.
3  *
4  * SPDX-License-Identifier: Apache-2.0 or MIT
5  */
6 
7 #include "common/oscore_edhoc_error.h"
8 #include "common/byte_array.h"
9 
10 #include "cbor/edhoc_encode_int_type.h"
11 #include "cbor/edhoc_decode_int_type.h"
12 
encode_int(const int32_t * in,uint32_t in_len,struct byte_array * out)13 enum err encode_int(const int32_t *in, uint32_t in_len, struct byte_array *out)
14 {
15 	size_t payload_len_out;
16 	TRY_EXPECT(cbor_encode_int_type_i(out->ptr, out->len, in,
17 					  &payload_len_out),
18 		   0);
19 	out->len = (uint32_t)payload_len_out;
20 	return ok;
21 }
22 
decode_int(const struct byte_array * in,int32_t * out)23 enum err decode_int(const struct byte_array *in, int32_t *out)
24 {
25 	size_t decode_len = 0;
26 	TRY_EXPECT(cbor_decode_int_type_i(in->ptr, in->len, out, &decode_len),
27 		   0);
28 	if (decode_len != 1) {
29 		return cbor_decoding_error;
30 	}
31 	return ok;
32 }