From 7424be8e0b033fd6466d517d6a8e3f0fb545dd59 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 31 Mar 2025 16:01:23 -0500 Subject: Decouple the checksodiumcb function from ALWAYS_CHECK_LIBSODIUM into its own macro --- src/encryption.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/encryption.h') diff --git a/src/encryption.h b/src/encryption.h index 1bdd2b9..1f04dae 100644 --- a/src/encryption.h +++ b/src/encryption.h @@ -3,21 +3,33 @@ #include +#define CHUNKSIZE (1 << 9) + + // Determines whether any function that calls libsodium functions also checks to make sure libsodium is actually initialized. May // cause unexpected issues with early exiting due to libsodium failing to initialize properly. It's recommended that you just // manually run `sodium_init()` in some main or init function of your own so that you can deal with a potential error yourself -#define ___VXGG___ALWAYS_CHECK_LIBSODIUM___ 0 +#define ___VXGG___ALWAYS_CHECK_LIBSODIUM___ 1 + +// Grants access to the `vxgg_setsodiumfailcb` function, which can be used to set a custom callback for what to do when libsodium +// fails upon initialization +#define ___VXGG___USE_CLS_CALLBACK___ 1 + + -#define CHUNKSIZE (1 << 9) -// TODO: What the fuck was I thinking when I did any of this callback shit? Make this a different macro and decouple it from ALWAYS_CHECK #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 +// Checks if sodium is initialized. Initializes it if not. If `___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0`, it's possible to set an error callback to avoid exiting the entire program. Otherwise calls `error()` if libsodium can't initialize +void checksodium(void); + +#if ___VXGG___USE_CLS_CALLBACK___ > 0 // Definition for the callback function that fires when a call to checksodium fails typedef void (*vxgg_naclfailcb)(void*); // Sets the error callback for when libsodium fails. Runs `cb(data)` if `(sodium_init() < 0)` void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); +#endif #endif @@ -78,9 +90,6 @@ void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); ) #define PASSWORD_WORDS_LEN (STATIC_ARRAY_LEN(PASSWORD_WORDS)) -// Checks if sodium is initialized. Initializes it if not. If `___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0`, it's possible to set an error callback to avoid exiting the entire program. Otherwise calls `error()` if libsodium can't initialize -void checksodium(void); - // open() with the flags O_TMPFILE, O_WRONLY, O_CLOEXEC, and O_SYNC. Opened with mode S_IRUSR, S_IWUSR int maketmp(const char * const dest); -- cgit v1.2.3