Move `MBEDTLS_ERR_ADD` macro and functions to `error.*`
`error.c` and error.h are the more logical place to keep this code and it
prevents issues with building `common.c` and conflicts with other projects
that use mbedtls (such as mbedOS).
`error.c` has been automatically generated by first adding the code to
`error.fmt` and then running `./scripts/generate_errors.pl`.
Also add parenthesis to the addition in `MBEDTLS_ERR_ADD`.
Signed-off-by: Chris Jones <christopher.jones@arm.com>
diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h
index cd7731e..d060d17 100644
--- a/include/mbedtls/error.h
+++ b/include/mbedtls/error.h
@@ -114,6 +114,28 @@
#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001 /**< Generic error */
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E /**< This is a bug in the library */
+/** Helper macro and function to combine a high and low level error code.
+ *
+ * This function uses a hook (`mbedtls_test_err_add_hook`) to allow invasive
+ * testing of its inputs. This is used in the test infrastructure to report
+ * on errors when combining two error codes of the same level (e.g: two high
+ * or two low level errors).
+ *
+ * To set a hook use
+ * ```
+ * mbedtls_set_err_add_hook(&mbedtls_check_foo);
+ * ```
+ */
+#if defined(MBEDTLS_TEST_HOOKS)
+void mbedtls_set_err_add_hook( void *hook );
+int mbedtls_err_add( int high, int low, const char *file, int line );
+#define MBEDTLS_ERR_ADD( high, low ) \
+ ( mbedtls_err_add( high, low, __FILE__, __LINE__ ) )
+#else
+#define MBEDTLS_ERR_ADD( high, low ) \
+ ( ( high ) + ( low ) )
+#endif /* MBEDTLS_TEST_HOOKS */
+
/**
* \brief Translate a mbed TLS error code into a string representation,
* Result is truncated if necessary and always includes a terminating