diff options
Diffstat (limited to 'src/error.c')
-rw-r--r-- | src/error.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/error.c b/src/error.c index e52cd4d..034aa72 100644 --- a/src/error.c +++ b/src/error.c @@ -20,17 +20,17 @@ static const char* err_msgs[] = "Invalid PKCS7 padding (wrong key?)", }; -const char* aesni_strerror(AesNI_ErrorCode ec) +const char* aesni_strerror(AesNI_StatusCode ec) { return err_msgs[ec]; } -static size_t aesni_format_error_simple( +static size_t aesni_format_error_strerror( const AesNI_ErrorDetails* err_details,\ char* dest, size_t dest_size) { - const AesNI_ErrorCode ec = aesni_get_error_code(err_details); + const AesNI_StatusCode ec = aesni_get_error_code(err_details); const char* const msg = aesni_strerror(ec); if (dest == NULL && dest_size == 0) @@ -60,9 +60,9 @@ typedef size_t (*AesNI_ErrorFormatter)(const AesNI_ErrorDetails*, char*, size_t) static AesNI_ErrorFormatter err_formatters[] = { - &aesni_format_error_simple, + &aesni_format_error_strerror, &aesni_format_error_null_argument, - &aesni_format_error_simple, + &aesni_format_error_strerror, }; size_t aesni_format_error( @@ -75,44 +75,37 @@ size_t aesni_format_error( return err_formatters[err_details->ec](err_details, dest, dest_size); } -static void aesni_make_error( +static AesNI_StatusCode aesni_make_error( AesNI_ErrorDetails* err_details, - AesNI_ErrorCode ec) + AesNI_StatusCode ec) { if (err_details == NULL) - return; + return ec; - err_details->ec = ec; + return err_details->ec = ec; } -void aesni_make_error_success( +AesNI_StatusCode aesni_make_error_success( AesNI_ErrorDetails* err_details) { - if (err_details == NULL) - return; - - aesni_make_error(err_details, AESNI_ERROR_SUCCESS); + return aesni_make_error(err_details, AESNI_SUCCESS); } -void aesni_make_error_null_argument( +AesNI_StatusCode aesni_make_error_null_argument( AesNI_ErrorDetails* err_details, const char* arg_name) { - if (err_details == NULL) - return; - - aesni_make_error(err_details, AESNI_ERROR_NULL_ARGUMENT); + AesNI_StatusCode status = aesni_make_error(err_details, AESNI_ERROR_NULL_ARGUMENT); const size_t arg_name_size = sizeof(err_details->params.null_arg.arg_name); strncpy(err_details->params.null_arg.arg_name, arg_name, arg_name_size); err_details->params.null_arg.arg_name[arg_name_size - 1] = '\0'; + + return status; } -void aesni_make_error_invalid_pkcs7_padding( +AesNI_StatusCode aesni_make_error_invalid_pkcs7_padding( AesNI_ErrorDetails* err_details) { - if (err_details == NULL) - return; - - aesni_make_error(err_details, AESNI_ERROR_INVALID_PKCS7_PADDING); + return aesni_make_error(err_details, AESNI_ERROR_INVALID_PKCS7_PADDING); } |