From dceecd80f76fb0c143ad89caaa06c0339cc9d521 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 15 Nov 2011 16:38:34 +0000 Subject: [PATCH] - Adapted error generation to include ASN.1 changes and have Windows snprintf macro --- library/error.c | 30 +++++++++++++++++------------- scripts/generate_errors.pl | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/library/error.c b/library/error.c index 9cf68d4b7..a792960af 100644 --- a/library/error.c +++ b/library/error.c @@ -90,6 +90,10 @@ #include +#if defined _MSC_VER && !defined snprintf +#define snprintf _snprintf +#endif + void error_strerror( int ret, char *buf, size_t buflen ) { size_t len; @@ -325,6 +329,19 @@ void error_strerror( int ret, char *buf, size_t buflen ) snprintf( buf, buflen, "AES - Invalid data input length" ); #endif /* POLARSSL_AES_C */ +#if defined(POLARSSL_ASN1_PARSE_C) + if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) ) + snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); + if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) ) + snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); + if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) ) + snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); + if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) ) + snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); + if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) ) + snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" ); +#endif /* POLARSSL_ASN1_PARSE_C */ + #if defined(POLARSSL_BASE64_C) if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) ) snprintf( buf, buflen, "BASE64 - Output buffer too small" ); @@ -391,19 +408,6 @@ void error_strerror( int ret, char *buf, size_t buflen ) snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); #endif /* POLARSSL_PADLOCK_C */ -#if defined(POLARSSL_X509_PARSE_C) - if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) ) - snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); - if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) ) - snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); - if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) ) - snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); - if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) ) - snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); - if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) ) - snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" ); -#endif /* POLARSSL_X509_PARSE_C */ - #if defined(POLARSSL_XTEA_C) if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) ) snprintf( buf, buflen, "XTEA - The data input has an invalid length" ); diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index b2d038e0e..5ea83811d 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -45,7 +45,7 @@ while (my $line = ) my $define_name = $module_name; $define_name = "X509_PARSE" if ($define_name eq "X509"); - $define_name = "X509_PARSE" if ($define_name eq "ASN1"); + $define_name = "ASN1_PARSE" if ($define_name eq "ASN1"); $define_name = "SSL_TLS" if ($define_name eq "SSL"); my $include_name = $module_name;