blob: c4af82c3af9b82ebc7e69aa1af183f26f1cd7459 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
|