From 5431fec6726c18234c9c28b014cc6f18a0d79884 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Fri, 6 Jun 2025 14:09:32 -0500 Subject: Style touchup --- src/encryption.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/encryption.c') diff --git a/src/encryption.c b/src/encryption.c index 3530eed..3bf9dd4 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -1,3 +1,5 @@ +// TODO: Go back and make sure every function has proper error handling + #define _GNU_SOURCE #include "encryption.h" @@ -70,12 +72,13 @@ void checksodium(void) { #endif int maketmp(const char * const dest) { - if(!dest) - RETURNWERR(EINVAL, -1); + if(!dest) ERRRET(EINVAL, -1); return open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); } int linkto(const char * const target, int tgfd) { + if(!target) ERRRET(EINVAL, -1); + char *path = NULL; asprintf(&path, "/proc/self/fd/%d", tgfd); if(!path) @@ -129,11 +132,11 @@ int decryptto(const char * const encrypted, const char * const target, const uns #endif if(!encrypted) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!target) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!key) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); FILE *src, *dst; if(!(src = fopen(encrypted, "rb"))) @@ -174,11 +177,11 @@ int encrypttofile(FILE *src, FILE *dst, const unsigned char key[crypto_secretstr #endif if(!src) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!dst) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!key) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); // Write the header crypto_secretstream_xchacha20poly1305_init_push(&state, header, key); @@ -217,11 +220,11 @@ int decrypttofile(FILE *src, FILE *dst, const unsigned char key[crypto_secretstr #endif if(!src) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!dst) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); if(!key) - RETURNWERR(EINVAL, -1); + ERRRET(EINVAL, -1); // Read the header if(fread(header, 1, sizeof(header), src) < sizeof(header)) -- cgit v1.2.3