From 6cb9e09a87e5439da136e14ff4e8dfcf26a47d8b Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 9 Dec 2022 18:55:18 +0100 Subject: [PATCH] implemented encryption in logger NOTE: This was pretty big change, I hope everything is cool --- src/logger/lib/logger.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/logger/lib/logger.c b/src/logger/lib/logger.c index 2bd26c2..ce5f440 100644 --- a/src/logger/lib/logger.c +++ b/src/logger/lib/logger.c @@ -29,6 +29,9 @@ along with this program. If not, see . #include +#include +#include + logFile initLogger(char *directoryPath) { //VARIABLES @@ -106,14 +109,32 @@ void writeLog(int loggerFile, char *logMessage) } //VARIABLES - char *buffer = malloc(strlen(WRITE_FORMAT) + strlen(logMessage) + 2); + char *buffer = NULL; + char *message = NULL; //COPY OF logMessage time_t timeL = time(NULL); struct tm tm = *localtime(&timeL); + logFlags flags = getLogFlags(); - sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, logMessage); //LOAD MESSAGE + if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED + { + outputFlags encrypted = encryptText(logMessage, flags.key); //ENCRYPT + + message = strdup(encrypted.outputText); //COPY + + //DEALLOCATION + free(encrypted.usedKey); + } else //FUCK ENCRYPTION, LET'S DO IT; WHY WOULD WE EVEN USE WHY2-CORE? HUH? + { + message = strdup(logMessage); //COPY + } + + buffer = malloc(strlen(WRITE_FORMAT) + strlen(message) + 2); //ALLOCATE + + sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, message); //LOAD MESSAGE (void) (write(loggerFile, buffer, strlen(buffer)) + 1); //TODO: Try to create some function for processing exit value //DEALLOCATION free(buffer); + free(message); } \ No newline at end of file