diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 03:25:03 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 03:25:03 +0300 |
commit | 35f3497d371a0a05098fcfdbe6e40d91095ef06c (patch) | |
tree | b9bbce2bf6c8b16b1ab837743425c29b4c4e2bf4 /src/error.c | |
parent | add `assert`s (diff) | |
download | aes-tools-35f3497d371a0a05098fcfdbe6e40d91095ef06c.tar.gz aes-tools-35f3497d371a0a05098fcfdbe6e40d91095ef06c.zip |
add error codes & messages to the library
Diffstat (limited to 'src/error.c')
-rw-r--r-- | src/error.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..c4af82c --- /dev/null +++ b/src/error.c @@ -0,0 +1,66 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#include <aesni/all.h> + +#include <stdlib.h> +#include <string.h> + +static const char* err_msgs[] = +{ + "Success", + "Invalid argument value NULL", + "Invalid PKCS7 padding (wrong key?)", +}; + +const char* aesni_strerror(AesNI_ErrorCode ec) +{ + return err_msgs[ec]; +} + +static void aesni_make_error( + AesNI_ErrorDetails* err_details, + AesNI_ErrorCode ec) +{ + if (err_details == NULL) + return; + + err_details->ec = ec; +} + +void aesni_make_error_success( + AesNI_ErrorDetails* err_details) +{ + if (err_details == NULL) + return; + + aesni_make_error(err_details, AESNI_ERROR_SUCCESS); +} + +void 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); + + 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'; +} + +void 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); +} |