aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/aes
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-07-23 13:00:23 +0200
committerEgor Tensin <egor@tensin.name>2026-07-23 13:11:27 +0200
commit77ff39ce2e659dd72e00999467a3cb769fc92894 (patch)
treee879cb58bdd25768251c4208276730da63d24158 /aes
parentaes/error: fix missing error message (diff)
downloadaes-tools-77ff39ce2e659dd72e00999467a3cb769fc92894.tar.gz
aes-tools-77ff39ce2e659dd72e00999467a3cb769fc92894.zip
aes/error: add static asserts to prevent missing error messages
Diffstat (limited to 'aes')
-rw-r--r--aes/CMakeLists.txt3
-rw-r--r--aes/include/aes/error.h1
-rw-r--r--aes/src/error.c10
3 files changed, 14 insertions, 0 deletions
diff --git a/aes/CMakeLists.txt b/aes/CMakeLists.txt
index e665b94..e48fe24 100644
--- a/aes/CMakeLists.txt
+++ b/aes/CMakeLists.txt
@@ -1,3 +1,6 @@
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_STANDARD_REQUIRED ON)
+
option(AES_TOOLS_ASM "Use the assembly language implementation instead of the one in C")
file(GLOB_RECURSE aes_include CONFIGURE_DEPENDS "include/*.h")
diff --git a/aes/include/aes/error.h b/aes/include/aes/error.h
index 524184e..cd36b6e 100644
--- a/aes/include/aes/error.h
+++ b/aes/include/aes/error.h
@@ -22,6 +22,7 @@ typedef enum {
AES_MISSING_PADDING_ERROR,
AES_MEMORY_ALLOCATION_ERROR,
AES_MODE_REQUIRES_INIT_VECTOR_ERROR,
+ AesErrorCount,
} AES_StatusCode;
static inline int aes_is_error(AES_StatusCode ec) {
diff --git a/aes/src/error.c b/aes/src/error.c
index 6a7a2c1..3ee57b3 100644
--- a/aes/src/error.c
+++ b/aes/src/error.c
@@ -59,6 +59,11 @@ static const char* aes_strerror_messages[] = {
"Encryption mode requires init vector",
};
+_Static_assert(
+ sizeof(aes_strerror_messages) / sizeof(aes_strerror_messages[0]) == AesErrorCount,
+ "Missing error message"
+);
+
const char* aes_strerror(AES_StatusCode ec) {
return aes_strerror_messages[ec];
}
@@ -137,6 +142,11 @@ static AES_ErrorFormatter err_formatters[] = {
&aes_format_error_strerror,
};
+_Static_assert(
+ sizeof(err_formatters) / sizeof(err_formatters[0]) == AesErrorCount,
+ "Missing error formatter"
+);
+
size_t aes_format_error(const AES_ErrorDetails* err_details, char* dest, size_t dest_size) {
assert(err_details);