Skip to content

Commit 5f6e69d

Browse files
Merge pull request #9693 from Harry-Ramsey/split-revert-error-development
Split error.h and move back error.c to mbedtls
2 parents 4e9d77e + 08007ed commit 5f6e69d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+205
-174
lines changed

include/mbedtls/error.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* \file error.h
3+
*
4+
* \brief Error to string translation
5+
*/
6+
/*
7+
* Copyright The Mbed TLS Contributors
8+
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9+
*/
10+
#ifndef MBEDTLS_ERROR_H
11+
#define MBEDTLS_ERROR_H
12+
13+
#include "mbedtls/build_info.h"
14+
#include "mbedtls/error_common.h"
15+
16+
#include <stddef.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
/**
23+
* \brief Translate an Mbed TLS error code into a string representation.
24+
* The result is truncated if necessary and always includes a
25+
* terminating null byte.
26+
*
27+
* \param errnum error code
28+
* \param buffer buffer to place representation in
29+
* \param buflen length of the buffer
30+
*/
31+
void mbedtls_strerror(int errnum, char *buffer, size_t buflen);
32+
33+
/**
34+
* \brief Translate the high-level part of an Mbed TLS error code into a string
35+
* representation.
36+
*
37+
* This function returns a const pointer to an un-modifiable string. The caller
38+
* must not try to modify the string. It is intended to be used mostly for
39+
* logging purposes.
40+
*
41+
* \param error_code error code
42+
*
43+
* \return The string representation of the error code, or \c NULL if the error
44+
* code is unknown.
45+
*/
46+
const char *mbedtls_high_level_strerr(int error_code);
47+
48+
/**
49+
* \brief Translate the low-level part of an Mbed TLS error code into a string
50+
* representation.
51+
*
52+
* This function returns a const pointer to an un-modifiable string. The caller
53+
* must not try to modify the string. It is intended to be used mostly for
54+
* logging purposes.
55+
*
56+
* \param error_code error code
57+
*
58+
* \return The string representation of the error code, or \c NULL if the error
59+
* code is unknown.
60+
*/
61+
const char *mbedtls_low_level_strerr(int error_code);
62+
63+
#ifdef __cplusplus
64+
}
65+
#endif
66+
67+
#endif /* error.h */

library/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(src_x509
2+
error.c
23
pkcs7.c
34
x509.c
45
x509_create.c
@@ -34,6 +35,26 @@ set(src_tls
3435
)
3536

3637
if(GEN_FILES)
38+
find_package(Perl REQUIRED)
39+
40+
file(GLOB crypto_error_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/*.h)
41+
file(GLOB tls_error_headers ${MBEDTLS_DIR}/include/mbedtls/*.h)
42+
add_custom_command(
43+
OUTPUT
44+
${CMAKE_CURRENT_BINARY_DIR}/error.c
45+
COMMAND
46+
${PERL_EXECUTABLE}
47+
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl
48+
${CMAKE_CURRENT_SOURCE_DIR}/../tf-psa-crypto/drivers/builtin/include/mbedtls
49+
${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls
50+
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files
51+
${CMAKE_CURRENT_BINARY_DIR}/${TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_DIR}/error.c
52+
DEPENDS
53+
${MBEDTLS_DIR}/scripts/generate_errors.pl
54+
${crypto_error_headers}
55+
${tls_error_headers}
56+
${MBEDTLS_DIR}/scripts/data_files/error.fmt
57+
)
3758
add_custom_command(
3859
OUTPUT
3960
${CMAKE_CURRENT_BINARY_DIR}/version_features.c
@@ -62,6 +83,7 @@ if(GEN_FILES)
6283
${tls_error_headers}
6384
)
6485
else()
86+
link_to_source(error.c)
6587
link_to_source(version_features.c)
6688
link_to_source(ssl_debug_helpers_generated.c)
6789
endif()

library/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TF_PSA_CRYPTO_CORE_PATH = $(MBEDTLS_PATH)/tf-psa-crypto/core
66
TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH = $(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/src
77

88
GENERATED_FILES := \
9-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.c \
9+
error.c \
1010
version_features.c \
1111
ssl_debug_helpers_generated.c \
1212
$(TF_PSA_CRYPTO_CORE_PATH)/psa_crypto_driver_wrappers.h \
@@ -148,7 +148,6 @@ OBJS_CRYPTO= \
148148
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/ecp_curves_new.o \
149149
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/entropy.o \
150150
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/entropy_poll.o \
151-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.o \
152151
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/gcm.o \
153152
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/hkdf.o \
154153
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/hmac_drbg.o \
@@ -206,6 +205,7 @@ OBJS_X509= \
206205
x509write_crt.o \
207206
x509write_csr.o \
208207
pkcs7.o \
208+
error.o \
209209
# This line is intentionally left blank
210210

211211
OBJS_TLS= \
@@ -357,10 +357,10 @@ else
357357
gen_file_dep = |
358358
endif
359359

360-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.c: $(gen_file_dep) ../scripts/generate_errors.pl
361-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.c: $(gen_file_dep) ../scripts/data_files/error.fmt
362-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
363-
$(TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH)/error.c:
360+
error.c: $(gen_file_dep) ../scripts/generate_errors.pl
361+
error.c: $(gen_file_dep) ../scripts/data_files/error.fmt
362+
error.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
363+
error.c:
364364
echo " Gen $@"
365365
$(PERL) ../scripts/generate_errors.pl
366366

programs/pkey/gen_key.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ int main(int argc, char *argv[])
453453

454454
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
455455
#ifdef MBEDTLS_ERROR_C
456-
mbedtls_strerror(ret, buf, sizeof(buf));
457-
mbedtls_printf(" - %s\n", buf);
456+
mbedtls_printf("Error code: %d", ret);
457+
/* mbedtls_strerror(ret, buf, sizeof(buf));
458+
mbedtls_printf(" - %s\n", buf); */
458459
#else
459460
mbedtls_printf("\n");
460461
#endif

programs/pkey/key_app.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ int main(int argc, char *argv[])
347347

348348
#if defined(MBEDTLS_ERROR_C)
349349
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
350-
mbedtls_strerror(ret, buf, sizeof(buf));
351-
mbedtls_printf(" ! Last error was: %s\n", buf);
350+
mbedtls_printf("Error code: %d", ret);
351+
/* mbedtls_strerror(ret, buf, sizeof(buf));
352+
mbedtls_printf(" ! Last error was: %s\n", buf); */
352353
}
353354
#endif
354355

programs/pkey/key_app_writer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,9 @@ int main(int argc, char *argv[])
469469

470470
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
471471
#ifdef MBEDTLS_ERROR_C
472-
mbedtls_strerror(ret, buf, sizeof(buf));
473-
mbedtls_printf(" - %s\n", buf);
472+
mbedtls_printf("Error code: %d", ret);
473+
/* mbedtls_strerror(ret, buf, sizeof(buf));
474+
mbedtls_printf(" - %s\n", buf); */
474475
#else
475476
mbedtls_printf("\n");
476477
#endif

programs/pkey/pk_decrypt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ int main(int argc, char *argv[])
142142

143143
#if defined(MBEDTLS_ERROR_C)
144144
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
145-
mbedtls_strerror(ret, (char *) buf, sizeof(buf));
146-
mbedtls_printf(" ! Last error was: %s\n", buf);
145+
mbedtls_printf("Error code: %d", ret);
146+
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
147+
mbedtls_printf(" ! Last error was: %s\n", buf); */
147148
}
148149
#endif
149150

programs/pkey/pk_encrypt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ int main(int argc, char *argv[])
143143

144144
#if defined(MBEDTLS_ERROR_C)
145145
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
146-
mbedtls_strerror(ret, (char *) buf, sizeof(buf));
147-
mbedtls_printf(" ! Last error was: %s\n", buf);
146+
mbedtls_printf("Error code: %d", ret);
147+
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
148+
mbedtls_printf(" ! Last error was: %s\n", buf); */
148149
}
149150
#endif
150151

programs/pkey/pk_sign.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ int main(int argc, char *argv[])
143143

144144
#if defined(MBEDTLS_ERROR_C)
145145
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
146-
mbedtls_strerror(ret, (char *) buf, sizeof(buf));
147-
mbedtls_printf(" ! Last error was: %s\n", buf);
146+
mbedtls_printf("Error code: %d", ret);
147+
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
148+
mbedtls_printf(" ! Last error was: %s\n", buf); */
148149
}
149150
#endif
150151

programs/pkey/pk_verify.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ int main(int argc, char *argv[])
117117

118118
#if defined(MBEDTLS_ERROR_C)
119119
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
120-
mbedtls_strerror(ret, (char *) buf, sizeof(buf));
121-
mbedtls_printf(" ! Last error was: %s\n", buf);
120+
mbedtls_printf("Error code: %d", ret);
121+
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
122+
mbedtls_printf(" ! Last error was: %s\n", buf); */
122123
}
123124
#endif
124125

0 commit comments

Comments
 (0)