Address review comments
1. The functions mbedtls_high_level_strerr and mbedtls_low_level_strerr
accept any error code and extract the high-level and low-level parts
respectively.
2. Documentation updates.
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
diff --git a/library/error.c b/library/error.c
index ee1f8b7..38b6580 100644
--- a/library/error.c
+++ b/library/error.c
@@ -215,9 +215,16 @@
const char * mbedtls_high_level_strerr( int error_code )
{
+ int high_level_error_code;
const char *error_description = NULL;
- switch( error_code )
+ if( error_code < 0 )
+ error_code = -error_code;
+
+ /* Extract the high-level part from the error code. */
+ high_level_error_code = error_code & 0xFF80;
+
+ switch( high_level_error_code )
{
/* Begin Auto-Generated Code. */
#if defined(MBEDTLS_CIPHER_C)
@@ -725,9 +732,16 @@
const char * mbedtls_low_level_strerr( int error_code )
{
+ int low_level_error_code;
const char *error_description = NULL;
- switch( error_code )
+ if( error_code < 0 )
+ error_code = -error_code;
+
+ /* Extract the low-level part from the error code. */
+ low_level_error_code = error_code & ~0xFF80;
+
+ switch( low_level_error_code )
{
/* Begin Auto-Generated Code. */
#if defined(MBEDTLS_AES_C)
@@ -1154,7 +1168,7 @@
use_ret = ret & 0xFF80;
// Translate high level error code.
- high_level_error_description = mbedtls_high_level_strerr(use_ret);
+ high_level_error_description = mbedtls_high_level_strerr( ret );
if( high_level_error_description == NULL )
mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
@@ -1191,7 +1205,7 @@
}
// Translate low level error code.
- low_level_error_description = mbedtls_low_level_strerr( use_ret );
+ low_level_error_description = mbedtls_low_level_strerr( ret );
if( low_level_error_description == NULL )
mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );