boot_serial: Update zcbor files from zcbor 0.7.0

Updates zcbor files from version 0.7.0, needed for size variable
support.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index e8afbfe..c6c58bf 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -153,7 +153,7 @@
                                       int len, zcbor_state_t *cs);
 
 #define zcbor_tstr_put_lit_cast(state, string) \
-	zcbor_tstr_encode_ptr(state, (uint8_t *)string, sizeof(string) - 1)
+	zcbor_tstr_encode_ptr(state, (char *)string, sizeof(string) - 1)
 
 #ifndef MCUBOOT_USE_SNPRINTF
 /*
@@ -312,7 +312,7 @@
 
             bs_list_img_ver((char *)tmpbuf, sizeof(tmpbuf), &hdr.ih_ver);
 
-            zcbor_tstr_encode_ptr(cbor_state, tmpbuf, strlen((char *)tmpbuf));
+            zcbor_tstr_encode_ptr(cbor_state, (char *)tmpbuf, strlen((char *)tmpbuf));
             zcbor_map_end_encode(cbor_state, 20);
         }
     }
diff --git a/boot/boot_serial/src/regenerate_serial_recovery_cbor.sh b/boot/boot_serial/src/regenerate_serial_recovery_cbor.sh
index 1f2137a..b56c270 100755
--- a/boot/boot_serial/src/regenerate_serial_recovery_cbor.sh
+++ b/boot/boot_serial/src/regenerate_serial_recovery_cbor.sh
@@ -24,7 +24,7 @@
 
 
 echo "Generating serial_recovery_cbor.c|h"
-zcbor -c serial_recovery.cddl code -d -t Upload --oc serial_recovery_cbor.c --oh serial_recovery_cbor.h --time-header --copy-sources
+zcbor code -c serial_recovery.cddl -d -t Upload --oc serial_recovery_cbor.c --oh serial_recovery_cbor.h --time-header --copy-sources
 
 add_copyright() {
 echo "$(printf '/*
diff --git a/boot/boot_serial/src/serial_recovery_cbor.c b/boot/boot_serial/src/serial_recovery_cbor.c
index d84d70e..cda489f 100644
--- a/boot/boot_serial/src/serial_recovery_cbor.c
+++ b/boot/boot_serial/src/serial_recovery_cbor.c
@@ -1,13 +1,13 @@
 /*
- * Copyright (c) 2022 Nordic Semiconductor ASA
+ * Copyright (c) 2023 Nordic Semiconductor ASA
  *
  * SPDX-License-Identifier: Apache-2.0
  */
 
 /*
- * Generated using zcbor version 0.4.0
+ * Generated using zcbor version 0.7.0
  * https://github.com/NordicSemiconductor/zcbor
- * at: 2022-03-31 12:37:11
+ * at: 2023-04-14 11:34:28
  * Generated with a --default-max-qty of 3
  */
 
@@ -28,6 +28,10 @@
 #error "The type file was generated with a different default_max_qty than this file"
 #endif
 
+static bool decode_Member(zcbor_state_t *state, struct Member_ *result);
+static bool decode_repeated_Upload_members(zcbor_state_t *state, struct Upload_members *result);
+static bool decode_Upload(zcbor_state_t *state, struct Upload *result);
+
 
 static bool decode_Member(
 		zcbor_state_t *state, struct Member_ *result)
@@ -37,15 +41,15 @@
 	bool int_res;
 
 	bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"image", tmp_str.len = sizeof("image") - 1, &tmp_str)))))
-	&& (zcbor_int32_decode(state, (&(*result)._Member_image)))) && (((*result)._Member_choice = _Member_image) || 1))
+	&& (zcbor_int32_decode(state, (&(*result)._Member_image)))) && (((*result)._Member_choice = _Member_image), true))
 	|| (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"data", tmp_str.len = sizeof("data") - 1, &tmp_str)))))
-	&& (zcbor_bstr_decode(state, (&(*result)._Member_data)))) && (((*result)._Member_choice = _Member_data) || 1)))
+	&& (zcbor_bstr_decode(state, (&(*result)._Member_data)))) && (((*result)._Member_choice = _Member_data), true)))
 	|| (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"len", tmp_str.len = sizeof("len") - 1, &tmp_str)))))
-	&& (zcbor_int32_decode(state, (&(*result)._Member_len)))) && (((*result)._Member_choice = _Member_len) || 1)))
+	&& (zcbor_int32_decode(state, (&(*result)._Member_len)))) && (((*result)._Member_choice = _Member_len), true)))
 	|| (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"off", tmp_str.len = sizeof("off") - 1, &tmp_str)))))
-	&& (zcbor_int32_decode(state, (&(*result)._Member_off)))) && (((*result)._Member_choice = _Member_off) || 1)))
+	&& (zcbor_int32_decode(state, (&(*result)._Member_off)))) && (((*result)._Member_choice = _Member_off), true)))
 	|| (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"sha", tmp_str.len = sizeof("sha") - 1, &tmp_str)))))
-	&& (zcbor_bstr_decode(state, (&(*result)._Member_sha)))) && (((*result)._Member_choice = _Member_sha) || 1)))), zcbor_union_end_code(state), int_res))));
+	&& (zcbor_bstr_decode(state, (&(*result)._Member_sha)))) && (((*result)._Member_choice = _Member_sha), true)))), zcbor_union_end_code(state), int_res))));
 
 	if (!tmp_result)
 		zcbor_trace();
@@ -98,8 +102,10 @@
 	}
 
 	if (!ret) {
-		int status = zcbor_pop_error(states);
-		return (status == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : status;
+		int err = zcbor_pop_error(states);
+
+		zcbor_print("Return error: %d\r\n", err);
+		return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err;
 	}
 	return ZCBOR_SUCCESS;
 }
diff --git a/boot/boot_serial/src/serial_recovery_cbor.h b/boot/boot_serial/src/serial_recovery_cbor.h
index 679fa71..90499ff 100644
--- a/boot/boot_serial/src/serial_recovery_cbor.h
+++ b/boot/boot_serial/src/serial_recovery_cbor.h
@@ -1,13 +1,13 @@
 /*
- * Copyright (c) 2022 Nordic Semiconductor ASA
+ * Copyright (c) 2023 Nordic Semiconductor ASA
  *
  * SPDX-License-Identifier: Apache-2.0
  */
 
 /*
- * Generated using zcbor version 0.4.0
+ * Generated using zcbor version 0.7.0
  * https://github.com/NordicSemiconductor/zcbor
- * at: 2022-03-31 12:37:11
+ * at: 2023-04-14 11:34:28
  * Generated with a --default-max-qty of 3
  */
 
@@ -27,6 +27,10 @@
 
 #include "serial_recovery_cbor_types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if DEFAULT_MAX_QTY != 3
 #error "The type file was generated with a different default_max_qty than this file"
 #endif
@@ -38,4 +42,8 @@
 		size_t *payload_len_out);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* SERIAL_RECOVERY_CBOR_H__ */
diff --git a/boot/boot_serial/src/serial_recovery_cbor_types.h b/boot/boot_serial/src/serial_recovery_cbor_types.h
index 6e5bd86..ebf0cd1 100644
--- a/boot/boot_serial/src/serial_recovery_cbor_types.h
+++ b/boot/boot_serial/src/serial_recovery_cbor_types.h
@@ -1,13 +1,13 @@
 /*
- * Copyright (c) 2022 Nordic Semiconductor ASA
+ * Copyright (c) 2023 Nordic Semiconductor ASA
  *
  * SPDX-License-Identifier: Apache-2.0
  */
 
 /*
- * Generated using zcbor version 0.4.0
+ * Generated using zcbor version 0.7.0
  * https://github.com/NordicSemiconductor/zcbor
- * at: 2022-03-31 12:37:11
+ * at: 2023-04-14 11:34:28
  * Generated with a --default-max-qty of 3
  */
 
@@ -25,6 +25,10 @@
 #include "zcbor_decode.h"
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /** Which value for --default-max-qty this file was created with.
  *
  *  The define is used in the other generated file to do a build-time
@@ -67,8 +71,11 @@
 
 struct Upload {
 	struct Upload_members _Upload_members[5];
-	uint_fast32_t _Upload_members_count;
+	size_t _Upload_members_count;
 };
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* SERIAL_RECOVERY_CBOR_TYPES_H__ */
diff --git a/boot/boot_serial/src/zcbor_common.c b/boot/boot_serial/src/zcbor_common.c
index 71962d6..e7a5e3a 100644
--- a/boot/boot_serial/src/zcbor_common.c
+++ b/boot/boot_serial/src/zcbor_common.c
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -128,7 +128,7 @@
 	return true;
 }
 
-bool zcbor_new_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		const uint8_t *payload, size_t payload_len, uint_fast32_t elem_count)
 {
 	state_array[0].payload = payload;
@@ -139,7 +139,7 @@
 	state_array[0].constant_state = NULL;
 
 	if(n_states < 2) {
-		return false;
+		return;
 	}
 
 	/* Use the last state as a struct zcbor_state_constant object. */
@@ -154,7 +154,6 @@
 	if (n_states > 2) {
 		state_array[0].constant_state->backup_list = &state_array[1];
 	}
-	return true;
 }
 
 void zcbor_update_state(zcbor_state_t *state,
diff --git a/boot/boot_serial/src/zcbor_common.h b/boot/boot_serial/src/zcbor_common.h
index eae2ffa..f44ded6 100644
--- a/boot/boot_serial/src/zcbor_common.h
+++ b/boot/boot_serial/src/zcbor_common.h
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -11,10 +11,14 @@
 
 #ifndef ZCBOR_COMMON_H__
 #define ZCBOR_COMMON_H__
+
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /** Convenience type that allows pointing to strings directly inside the payload
  *  without the need to copy out.
@@ -40,10 +44,10 @@
 #define ZCBOR_STRING_FRAGMENT_UNKNOWN_LENGTH SIZE_MAX
 
 #ifdef ZCBOR_VERBOSE
-#include <sys/printk.h>
-#define zcbor_trace() (printk("bytes left: %zu, byte: 0x%x, elem_count: 0x%" PRIxFAST32 ", %s:%d\n",\
-	(size_t)state->payload_end - (size_t)state->payload, *state->payload, \
-	state->elem_count, __FILE__, __LINE__))
+#include <zephyr/sys/printk.h>
+#define zcbor_trace() (printk("bytes left: %zu, byte: 0x%x, elem_count: 0x%" PRIxFAST32 ", err: %d, %s:%d\n",\
+	(size_t)state->payload_end - (size_t)state->payload, *state->payload, state->elem_count, \
+	state->constant_state ? state->constant_state->error : 0, __FILE__, __LINE__))
 
 #define zcbor_print_assert(expr, ...) \
 do { \
@@ -67,18 +71,34 @@
 		ZCBOR_FAIL(); \
 	} \
 } while(0)
+#define zcbor_assert_state(expr, ...) \
+do { \
+	if (!(expr)) { \
+		zcbor_print_assert(expr, __VA_ARGS__); \
+		ZCBOR_ERR(ZCBOR_ERR_ASSERTION); \
+	} \
+} while(0)
 #else
 #define zcbor_assert(expr, ...)
+#define zcbor_assert_state(expr, ...)
 #endif
 
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#ifndef ZCBOR_ARRAY_SIZE
+#define ZCBOR_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
+#if SIZE_MAX <= UINT64_MAX
+/** The ZCBOR_SUPPORTS_SIZE_T will be defined if processing of size_t type variables directly
+ * with zcbor_size_ functions is supported.
+**/
+#define ZCBOR_SUPPORTS_SIZE_T
+#else
+#warning "zcbor: Unsupported size_t encoding size"
+#endif
 
 struct zcbor_state_constant;
 
@@ -269,35 +289,48 @@
 bool zcbor_union_end_code(zcbor_state_t *state);
 
 /** Initialize a state with backups.
- *  One of the states in the array is used as a struct zcbor_state_constant object.
+ *  As long as n_states is more than 1, one of the states in the array is used
+ *  as a struct zcbor_state_constant object.
+ *  If there is no struct zcbor_state_constant (n_states == 1), error codes are
+ *  not available.
  *  This means that you get a state with (n_states - 2) backups.
- *  The constant state is mandatory so n_states must be at least 2.
  *  payload, payload_len, and elem_count are used to initialize the first state.
  *  in the array, which is the state that can be passed to cbor functions.
- *
- *  @retval false  if n_states < 2
- *  @retval true   otherwise
  */
-bool zcbor_new_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		const uint8_t *payload, size_t payload_len, uint_fast32_t elem_count);
 
 #ifdef ZCBOR_STOP_ON_ERROR
 /** Check stored error and fail if present, but only if stop_on_error is true. */
 static inline bool zcbor_check_error(const zcbor_state_t *state)
 {
-	return !(state->constant_state->stop_on_error && state->constant_state->error);
+	struct zcbor_state_constant  *cs = state->constant_state;
+	return !(cs && cs->stop_on_error && cs->error);
 }
 #endif
 
 /** Return the current error state, replacing it with SUCCESS. */
 static inline int zcbor_pop_error(zcbor_state_t *state)
 {
+	if (!state->constant_state) {
+		return ZCBOR_SUCCESS;
+	}
 	int err = state->constant_state->error;
 
 	state->constant_state->error = ZCBOR_SUCCESS;
 	return err;
 }
 
+/** Look at current error state without altering it */
+static inline int zcbor_peek_error(const zcbor_state_t *state)
+{
+	if (!state->constant_state) {
+		return ZCBOR_SUCCESS;
+	} else {
+		return state->constant_state->error;
+	}
+}
+
 /** Write the provided error to the error state. */
 static inline void zcbor_error(zcbor_state_t *state, int err)
 {
@@ -305,7 +338,9 @@
 	if (zcbor_check_error(state))
 #endif
 	{
-		state->constant_state->error = err;
+		if (state->constant_state) {
+			state->constant_state->error = err;
+		}
 	}
 }
 
@@ -368,4 +403,8 @@
 bool zcbor_splice_string_fragments(struct zcbor_string_fragment *fragments,
 		uint_fast32_t num_fragments, uint8_t *result, size_t *result_len);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ZCBOR_COMMON_H__ */
diff --git a/boot/boot_serial/src/zcbor_debug.h b/boot/boot_serial/src/zcbor_debug.h
index f34ad7f..5f9b477 100644
--- a/boot/boot_serial/src/zcbor_debug.h
+++ b/boot/boot_serial/src/zcbor_debug.h
@@ -6,11 +6,16 @@
 
 #ifndef ZCBOR_DEBUG_H__
 #define ZCBOR_DEBUG_H__
+
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include "zcbor_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 __attribute__((used))
 static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, uint32_t size)
 {
@@ -57,4 +62,8 @@
 	}
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ZCBOR_DEBUG_H__ */
diff --git a/boot/boot_serial/src/zcbor_decode.c b/boot/boot_serial/src/zcbor_decode.c
index e1d6678..ba357e1 100644
--- a/boot/boot_serial/src/zcbor_decode.c
+++ b/boot/boot_serial/src/zcbor_decode.c
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -33,7 +33,7 @@
 }
 
 /** Extract the major type, i.e. the first 3 bits of the header byte. */
-#define MAJOR_TYPE(header_byte) (((header_byte) >> 5) & 0x7)
+#define MAJOR_TYPE(header_byte) ((zcbor_major_type_t)(((header_byte) >> 5) & 0x7))
 
 /** Extract the additional info, i.e. the last 5 bits of the header byte. */
 #define ADDITIONAL(header_byte) ((header_byte) & 0x1F)
@@ -117,8 +117,8 @@
 		void *const result, uint_fast32_t result_len)
 {
 	zcbor_trace();
-	zcbor_assert(result_len != 0, "0-length result not supported.\r\n");
-	zcbor_assert(result != NULL, NULL);
+	zcbor_assert_state(result_len != 0, "0-length result not supported.\r\n");
+	zcbor_assert_state(result != NULL, NULL);
 
 	INITIAL_CHECKS();
 	ZCBOR_ERR_IF((state->elem_count == 0), ZCBOR_ERR_LOW_ELEM_COUNT);
@@ -160,28 +160,12 @@
 }
 
 
-bool zcbor_int32_decode(zcbor_state_t *state, int32_t *result)
-{
-	int64_t result64;
-
-	if (zcbor_int64_decode(state, &result64)) {
-		if (result64 > INT32_MAX) {
-			ERR_RESTORE(ZCBOR_ERR_INT_SIZE);
-		}
-		*result = (int32_t)result64;
-		return true;
-	} else {
-		ZCBOR_FAIL();
-	}
-}
-
-
-bool zcbor_int64_decode(zcbor_state_t *state, int64_t *result)
+bool zcbor_int_decode(zcbor_state_t *state, void *result_int, size_t int_size)
 {
 	INITIAL_CHECKS();
-	uint8_t major_type = MAJOR_TYPE(*state->payload);
-	uint64_t uint_result;
-	int64_t int_result;
+	zcbor_major_type_t major_type = MAJOR_TYPE(*state->payload);
+	uint8_t *result_uint8 = (uint8_t *)result_int;
+	int8_t *result_int8 = (int8_t *)result_int;
 
 	if (major_type != ZCBOR_MAJOR_TYPE_PINT
 		&& major_type != ZCBOR_MAJOR_TYPE_NINT) {
@@ -189,31 +173,42 @@
 		ZCBOR_ERR(ZCBOR_ERR_WRONG_TYPE);
 	}
 
-	if (!value_extract(state, &uint_result, sizeof(uint_result))) {
+	if (!value_extract(state, result_int, int_size)) {
 		ZCBOR_FAIL();
 	}
 
-	zcbor_print("uintval: %" PRIu64 "\r\n", uint_result);
-
-	int_result = (int64_t)uint_result;
-
-	if (int_result < 0) {
+#ifdef CONFIG_BIG_ENDIAN
+	if (result_int8[0] < 0) {
+#else
+	if (result_int8[int_size - 1] < 0) {
+#endif
 		/* Value is too large to fit in a signed integer. */
 		ERR_RESTORE(ZCBOR_ERR_INT_SIZE);
 	}
 
 	if (major_type == ZCBOR_MAJOR_TYPE_NINT) {
-		/* Convert from CBOR's representation. */
-		*result = -1 - int_result;
-	} else {
-		*result = int_result;
+		/* Convert from CBOR's representation by flipping all bits. */
+		for (int i = 0; i < int_size; i++) {
+			result_uint8[i] = (uint8_t)~result_uint8[i];
+		}
 	}
 
-	zcbor_print("val: %" PRIi64 "\r\n", *result);
 	return true;
 }
 
 
+bool zcbor_int32_decode(zcbor_state_t *state, int32_t *result)
+{
+	return zcbor_int_decode(state, result, sizeof(*result));
+}
+
+
+bool zcbor_int64_decode(zcbor_state_t *state, int64_t *result)
+{
+	return zcbor_int_decode(state, result, sizeof(*result));
+}
+
+
 bool zcbor_uint32_decode(zcbor_state_t *state, uint32_t *result)
 {
 	INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_PINT);
@@ -225,16 +220,38 @@
 }
 
 
+bool zcbor_int32_expect_union(zcbor_state_t *state, int32_t result)
+{
+	if (!zcbor_union_elem_code(state)) {
+		ZCBOR_FAIL();
+	}
+	return zcbor_int32_expect(state, result);
+}
+
+
+bool zcbor_int64_expect_union(zcbor_state_t *state, int64_t result)
+{
+	if (!zcbor_union_elem_code(state)) {
+		ZCBOR_FAIL();
+	}
+	return zcbor_int64_expect(state, result);
+}
+
+
 bool zcbor_uint32_expect_union(zcbor_state_t *state, uint32_t result)
 {
-	zcbor_union_elem_code(state);
+	if (!zcbor_union_elem_code(state)) {
+		ZCBOR_FAIL();
+	}
 	return zcbor_uint32_expect(state, result);
 }
 
 
 bool zcbor_uint64_expect_union(zcbor_state_t *state, uint64_t result)
 {
-	zcbor_union_elem_code(state);
+	if (!zcbor_union_elem_code(state)) {
+		ZCBOR_FAIL();
+	}
 	return zcbor_uint64_expect(state, result);
 }
 
@@ -272,6 +289,14 @@
 }
 
 
+#ifdef ZCBOR_SUPPORTS_SIZE_T
+bool zcbor_size_decode(zcbor_state_t *state, size_t *result)
+{
+	return value_extract(state, result, sizeof(size_t));
+}
+#endif
+
+
 bool zcbor_uint32_expect(zcbor_state_t *state, uint32_t result)
 {
 	return zcbor_uint64_expect(state, result);
@@ -293,6 +318,14 @@
 }
 
 
+#ifdef ZCBOR_SUPPORTS_SIZE_T
+bool zcbor_size_expect(zcbor_state_t *state, size_t result)
+{
+	return zcbor_uint64_expect(state, result);
+}
+#endif
+
+
 static bool str_start_decode(zcbor_state_t *state,
 		struct zcbor_string *result, zcbor_major_type_t exp_major_type)
 {
@@ -322,7 +355,6 @@
 bool zcbor_bstr_start_decode(zcbor_state_t *state, struct zcbor_string *result)
 {
 	struct zcbor_string dummy;
-
 	if (result == NULL) {
 		result = &dummy;
 	}
@@ -760,11 +792,11 @@
 
 bool zcbor_any_skip(zcbor_state_t *state, void *result)
 {
-	zcbor_assert(result == NULL,
+	zcbor_assert_state(result == NULL,
 			"'any' type cannot be returned, only skipped.\r\n");
 
 	INITIAL_CHECKS();
-	uint8_t major_type = MAJOR_TYPE(*state->payload);
+	zcbor_major_type_t major_type = MAJOR_TYPE(*state->payload);
 	uint8_t additional = ADDITIONAL(*state->payload);
 	uint_fast32_t value;
 	uint_fast32_t num_decode;
@@ -906,15 +938,15 @@
 	uint_fast32_t num_decode;
 	bool retval = zcbor_multi_decode(0, 1, &num_decode, decoder, state, result, 0);
 
-	zcbor_assert(retval, "zcbor_multi_decode should not fail with these parameters.\r\n");
+	zcbor_assert_state(retval, "zcbor_multi_decode should not fail with these parameters.\r\n");
 
 	*present = num_decode;
 	return retval;
 }
 
 
-bool zcbor_new_decode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_decode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		const uint8_t *payload, size_t payload_len, uint_fast32_t elem_count)
 {
-	return zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
+	zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
 }
diff --git a/boot/boot_serial/src/zcbor_decode.h b/boot/boot_serial/src/zcbor_decode.h
index 33a51fe..53ce94d 100644
--- a/boot/boot_serial/src/zcbor_decode.h
+++ b/boot/boot_serial/src/zcbor_decode.h
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -11,11 +11,16 @@
 
 #ifndef ZCBOR_DECODE_H__
 #define ZCBOR_DECODE_H__
+
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include "zcbor_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /** The zcbor_decode library provides functions for decoding CBOR data elements.
  *
  * See The README for an introduction to CBOR, including the meaning of pint,
@@ -39,6 +44,8 @@
 bool zcbor_int64_decode(zcbor_state_t *state, int64_t *result);
 bool zcbor_uint32_decode(zcbor_state_t *state, uint32_t *result);
 bool zcbor_uint64_decode(zcbor_state_t *state, uint64_t *result);
+bool zcbor_size_decode(zcbor_state_t *state, size_t *result);
+bool zcbor_int_decode(zcbor_state_t *state, void *result_int, size_t int_size);
 
 /** The following applies to all _expect() functions that don't have docs.
  *
@@ -54,11 +61,14 @@
 bool zcbor_int64_expect(zcbor_state_t *state, int64_t result);
 bool zcbor_uint32_expect(zcbor_state_t *state, uint32_t result);
 bool zcbor_uint64_expect(zcbor_state_t *state, uint64_t result);
+bool zcbor_size_expect(zcbor_state_t *state, size_t result);
 
-/** Consume and expect a pint with a certain value, within a union.
+/** Consume and expect a pint/nint with a certain value, within a union.
  *
- * Calls @ref zcbor_union_elem_code then @ref zcbor_uint32_expect.
+ * Calls @ref zcbor_union_elem_code then @ref zcbor_[u]int[32|64]_expect.
  */
+bool zcbor_int32_expect_union(zcbor_state_t *state, int32_t result);
+bool zcbor_int64_expect_union(zcbor_state_t *state, int64_t result);
 bool zcbor_uint32_expect_union(zcbor_state_t *state, uint32_t result);
 bool zcbor_uint64_expect_union(zcbor_state_t *state, uint64_t result);
 
@@ -74,13 +84,17 @@
  * @param[in]    string  The value to expect. A pointer to the string.
  * @param[in]    len     The length of the string pointed to by @p string.
  */
-static inline bool zcbor_bstr_expect_ptr(zcbor_state_t *state, uint8_t *ptr, size_t len)
+static inline bool zcbor_bstr_expect_ptr(zcbor_state_t *state, char const *ptr, size_t len)
 {
-	return zcbor_bstr_expect(state, &(struct zcbor_string){.value = ptr, .len = len});
+	struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
+
+	return zcbor_bstr_expect(state, &zs);
 }
-static inline bool zcbor_tstr_expect_ptr(zcbor_state_t *state, uint8_t *ptr, size_t len)
+static inline bool zcbor_tstr_expect_ptr(zcbor_state_t *state, char const *ptr, size_t len)
 {
-	return zcbor_tstr_expect(state, &(struct zcbor_string){.value = ptr, .len = len});
+	struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
+
+	return zcbor_tstr_expect(state, &zs);
 }
 
 
@@ -309,7 +323,7 @@
 		void *result);
 
 /** See @ref zcbor_new_state() */
-bool zcbor_new_decode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_decode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		const uint8_t *payload, size_t payload_len, uint_fast32_t elem_count);
 
 /** Convenience macro for declaring and initializing a state with backups.
@@ -317,10 +331,6 @@
  *  This gives you a state variable named @p name. The variable functions like
  *  a pointer.
  *
- *  The return value from @ref zcbor_new_encode_state can be safely ignored
- *  because the only error condition is n_states < 2, and this macro adds 2 to
- *  num_backups to get n_states, so it can never be < 2.
- *
  *  @param[in]  name          The name of the new state variable.
  *  @param[in]  num_backups   The number of backup slots to keep in the state.
  *  @param[in]  payload       The payload to work on.
@@ -330,7 +340,11 @@
 #define ZCBOR_STATE_D(name, num_backups, payload, payload_size, elem_count) \
 zcbor_state_t name[((num_backups) + 2)]; \
 do { \
-	(void)zcbor_new_decode_state(name, ARRAY_SIZE(name), payload, payload_size, elem_count); \
+	zcbor_new_decode_state(name, ZCBOR_ARRAY_SIZE(name), payload, payload_size, elem_count); \
 } while(0)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ZCBOR_DECODE_H__ */
diff --git a/boot/boot_serial/src/zcbor_encode.c b/boot/boot_serial/src/zcbor_encode.c
index 2a4d5e3..1929ceb 100644
--- a/boot/boot_serial/src/zcbor_encode.c
+++ b/boot/boot_serial/src/zcbor_encode.c
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -48,7 +48,7 @@
 	ZCBOR_CHECK_ERROR();
 	ZCBOR_CHECK_PAYLOAD();
 
-	zcbor_assert(additional < 32, NULL);
+	zcbor_assert_state(additional < 32, NULL);
 
 	*(state->payload_mut++) = (uint8_t)((major_type << 5) | (additional & 0x1F));
 	return true;
@@ -116,7 +116,7 @@
 	uint_fast32_t result_len)
 {
 #ifdef CONFIG_BIG_ENDIAN
-	return &((uint8_t *)input)[max_result_len - result_len];
+	return &((uint8_t *)input)[max_result_len - (result_len ? result_len : 1)];
 #else
 	return input;
 #endif
@@ -137,7 +137,7 @@
 static bool value_encode(zcbor_state_t *state, zcbor_major_type_t major_type,
 		const void *const input, uint_fast32_t max_result_len)
 {
-	zcbor_assert(max_result_len != 0, "0-length result not supported.\r\n");
+	zcbor_assert_state(max_result_len != 0, "0-length result not supported.\r\n");
 
 	uint_fast32_t result_len = get_result_len(input, max_result_len);
 	const void *const result = get_result(input, max_result_len, result_len);
@@ -146,26 +146,35 @@
 }
 
 
-bool zcbor_int32_put(zcbor_state_t *state, int32_t input)
-{
-	return zcbor_int64_put(state, input);
-}
-
-
-bool zcbor_int64_put(zcbor_state_t *state, int64_t input)
+bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_size)
 {
 	zcbor_major_type_t major_type;
+	uint8_t input_buf[8];
+	const uint8_t *input_uint8 = input_int;
+	const int8_t *input_int8 = input_int;
+	const uint8_t *input = input_int;
 
-	if (input < 0) {
-		major_type = ZCBOR_MAJOR_TYPE_NINT;
-		/* Convert from CBOR's representation. */
-		input = -1 - input;
-	} else {
-		major_type = ZCBOR_MAJOR_TYPE_PINT;
-		input = input;
+	if (int_size > sizeof(int64_t)) {
+		ZCBOR_ERR(ZCBOR_ERR_INT_SIZE);
 	}
 
-	if (!value_encode(state, major_type, &input, 8)) {
+#ifdef CONFIG_BIG_ENDIAN
+	if (input_int8[0] < 0) {
+#else
+	if (input_int8[int_size - 1] < 0) {
+#endif
+		major_type = ZCBOR_MAJOR_TYPE_NINT;
+
+		/* Convert to CBOR's representation by flipping all bits. */
+		for (int i = 0; i < int_size; i++) {
+			input_buf[i] = (uint8_t)~input_uint8[i];
+		}
+		input = input_buf;
+	} else {
+		major_type = ZCBOR_MAJOR_TYPE_PINT;
+	}
+
+	if (!value_encode(state, major_type, input, int_size)) {
 		ZCBOR_FAIL();
 	}
 
@@ -175,7 +184,13 @@
 
 bool zcbor_int32_encode(zcbor_state_t *state, const int32_t *input)
 {
-	return zcbor_int32_put(state, *input);
+	return zcbor_int_encode(state, input, sizeof(*input));
+}
+
+
+bool zcbor_int64_encode(zcbor_state_t *state, const int64_t *input)
+{
+	return zcbor_int_encode(state, input, sizeof(*input));
 }
 
 
@@ -198,12 +213,6 @@
 }
 
 
-bool zcbor_int64_encode(zcbor_state_t *state, const int64_t *input)
-{
-	return zcbor_int64_put(state, *input);
-}
-
-
 static bool uint64_encode(zcbor_state_t *state, const uint64_t *input,
 		zcbor_major_type_t major_type)
 {
@@ -223,6 +232,18 @@
 }
 
 
+bool zcbor_int32_put(zcbor_state_t *state, int32_t input)
+{
+	return zcbor_int_encode(state, &input, sizeof(input));
+}
+
+
+bool zcbor_int64_put(zcbor_state_t *state, int64_t input)
+{
+	return zcbor_int_encode(state, &input, sizeof(input));
+}
+
+
 bool zcbor_uint32_put(zcbor_state_t *state, uint32_t input)
 {
 	return zcbor_uint64_put(state, input);
@@ -238,6 +259,19 @@
 }
 
 
+#ifdef ZCBOR_SUPPORTS_SIZE_T
+bool zcbor_size_put(zcbor_state_t *state, size_t input)
+{
+	return zcbor_uint64_put(state, input);
+}
+
+
+bool zcbor_size_encode(zcbor_state_t *state, const size_t *input)
+{
+	return zcbor_size_put(state, *input);
+}
+#endif
+
 static bool str_start_encode(zcbor_state_t *state,
 		const struct zcbor_string *input, zcbor_major_type_t major_type)
 {
@@ -411,6 +445,15 @@
 
 	zcbor_print("list_count: %" PRIuFAST32 "\r\n", list_count);
 
+
+	/** If max_num is smaller than the actual number of encoded elements,
+	  * the value_encode() below will corrupt the data if the encoded
+	  * header is larger than the previously encoded header. */
+	if (header_len > max_header_len) {
+		zcbor_print("max_num too small.\r\n");
+		ZCBOR_ERR(ZCBOR_ERR_HIGH_ELEM_COUNT);
+	}
+
 	/* Reencode header of list now that we know the number of elements. */
 	if (!(value_encode(state, major_type, &list_count, sizeof(list_count)))) {
 		ZCBOR_FAIL();
@@ -419,9 +462,8 @@
 	if (max_header_len != header_len) {
 		const uint8_t *start = state->payload + max_header_len - header_len;
 		size_t body_size = (size_t)payload - (size_t)start;
-		memmove(state->payload_mut,
-			state->payload + max_header_len - header_len,
-			body_size);
+
+		memmove(state->payload_mut, start, body_size);
 		/* Reset payload pointer to end of list */
 		state->payload += body_size;
 	} else {
@@ -495,7 +537,7 @@
 
 bool zcbor_float64_encode(zcbor_state_t *state, const double *input)
 {
-	if (!value_encode(state, ZCBOR_MAJOR_TYPE_PRIM, input,
+	if (!value_encode_len(state, ZCBOR_MAJOR_TYPE_PRIM, input,
 			sizeof(*input))) {
 		ZCBOR_FAIL();
 	}
@@ -512,7 +554,7 @@
 
 bool zcbor_float32_encode(zcbor_state_t *state, const float *input)
 {
-	if (!value_encode(state, ZCBOR_MAJOR_TYPE_PRIM, input,
+	if (!value_encode_len(state, ZCBOR_MAJOR_TYPE_PRIM, input,
 			sizeof(*input))) {
 		ZCBOR_FAIL();
 	}
@@ -580,8 +622,8 @@
 }
 
 
-bool zcbor_new_encode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_encode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		uint8_t *payload, size_t payload_len, uint_fast32_t elem_count)
 {
-	return zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
+	zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
 }
diff --git a/boot/boot_serial/src/zcbor_encode.h b/boot/boot_serial/src/zcbor_encode.h
index e129021..40bcccf 100644
--- a/boot/boot_serial/src/zcbor_encode.h
+++ b/boot/boot_serial/src/zcbor_encode.h
@@ -1,6 +1,6 @@
 /*
  * This file has been copied from the zcbor library.
- * Commit zcbor 0.4.0
+ * Commit zcbor 0.7.0
  */
 
 /*
@@ -11,11 +11,16 @@
 
 #ifndef ZCBOR_ENCODE_H__
 #define ZCBOR_ENCODE_H__
+
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include "zcbor_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /** The zcbor_encode library provides functions for encoding CBOR data elements.
  *
  * See The README for an introduction to CBOR, including the meaning of pint,
@@ -35,17 +40,20 @@
 /** Encode a pint/nint. */
 bool zcbor_int32_put(zcbor_state_t *state, int32_t input);
 bool zcbor_int64_put(zcbor_state_t *state, int64_t input);
-bool zcbor_uint32_put(zcbor_state_t *state, uint32_t result);
+bool zcbor_uint32_put(zcbor_state_t *state, uint32_t input);
 bool zcbor_uint64_put(zcbor_state_t *state, uint64_t input);
+bool zcbor_size_put(zcbor_state_t *state, size_t input);
 
 /** Encode a pint/nint from a pointer.
  *
  *  Can be used for bulk encoding with @ref zcbor_multi_encode.
  */
+bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_size);
 bool zcbor_int32_encode(zcbor_state_t *state, const int32_t *input);
 bool zcbor_int64_encode(zcbor_state_t *state, const int64_t *input);
-bool zcbor_uint32_encode(zcbor_state_t *state, const uint32_t *result);
+bool zcbor_uint32_encode(zcbor_state_t *state, const uint32_t *input);
 bool zcbor_uint64_encode(zcbor_state_t *state, const uint64_t *input);
+bool zcbor_size_encode(zcbor_state_t *state, const size_t *input);
 
 /** Encode a bstr. */
 bool zcbor_bstr_encode(zcbor_state_t *state, const struct zcbor_string *input);
@@ -58,13 +66,17 @@
  * @param[in]    string  The value to encode. A pointer to the string
  * @param[in]    len     The length of the string pointed to by @p string.
  */
-static inline bool zcbor_bstr_encode_ptr(zcbor_state_t *state, uint8_t *ptr, size_t len)
+static inline bool zcbor_bstr_encode_ptr(zcbor_state_t *state, const char *ptr, size_t len)
 {
-	return zcbor_bstr_encode(state, &(struct zcbor_string){.value = ptr, .len = len});
+	const struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
+
+	return zcbor_bstr_encode(state, &zs);
 }
-static inline bool zcbor_tstr_encode_ptr(zcbor_state_t *state, uint8_t *ptr, size_t len)
+static inline bool zcbor_tstr_encode_ptr(zcbor_state_t *state, const char *ptr, size_t len)
 {
-	return zcbor_tstr_encode(state, &(struct zcbor_string){.value = ptr, .len = len});
+	const struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
+
+	return zcbor_tstr_encode(state, &zs);
 }
 
 /** Encode a string literal as a bstr/tstr.
@@ -253,7 +265,7 @@
 		const void *input);
 
 /** See @ref zcbor_new_state() */
-bool zcbor_new_encode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
+void zcbor_new_encode_state(zcbor_state_t *state_array, uint_fast32_t n_states,
 		uint8_t *payload, size_t payload_len, uint_fast32_t elem_count);
 
 /** Convenience macro for declaring and initializing a state with backups.
@@ -261,10 +273,6 @@
  *  This gives you a state variable named @p name. The variable functions like
  *  a pointer.
  *
- *  The return value from @ref zcbor_new_encode_state can be safely ignored
- *  because the only error condition is n_states < 2, and this macro adds 2 to
- *  num_backups to get n_states, so it can never be < 2.
- *
  *  @param[in]  name          The name of the new state variable.
  *  @param[in]  num_backups   The number of backup slots to keep in the state.
  *  @param[in]  payload       The payload to work on.
@@ -274,7 +282,11 @@
 #define ZCBOR_STATE_E(name, num_backups, payload, payload_size, elem_count) \
 zcbor_state_t name[((num_backups) + 2)]; \
 do { \
-	(void)zcbor_new_encode_state(name, ARRAY_SIZE(name), payload, payload_size, elem_count); \
+	zcbor_new_encode_state(name, ZCBOR_ARRAY_SIZE(name), payload, payload_size, elem_count); \
 } while(0)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ZCBOR_ENCODE_H__ */