From bbb09428d19a12268c4e9929910ab3333732d626 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 3 Feb 2023 17:03:46 +0100 Subject: [PATCH] renamed all 'public' identificators to snake_case I mean the identificators user gets in contact with --- include/flags.h | 18 +++++++-------- include/logger/flags.h | 4 ++-- include/misc.h | 4 ++-- src/core/app/main.c | 2 +- src/core/lib/decrypter.c | 18 +++++++-------- src/core/lib/flags.c | 4 ++-- src/core/lib/test/main.c | 22 +++++++++--------- src/core/lib/utils/misc.c | 46 +++++++++++++++++++------------------- src/logger/lib/logger.c | 2 +- src/logger/lib/test/main.c | 22 +++++++++--------- src/logger/lib/utils.c | 10 ++++----- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/include/flags.h b/include/flags.h index 605d476..27d935e 100644 --- a/include/flags.h +++ b/include/flags.h @@ -54,19 +54,19 @@ typedef char why2_bool; //READ THE NAME OR I WILL FIND YOU AND FUCK YOUR MOTHERF typedef int (*why2_encryption_operation_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK typedef struct { - why2_bool noCheck; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK - why2_bool noOutput; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING + why2_bool no_check; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK + why2_bool no_output; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED } why2_input_flags; typedef struct { - char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT - char *usedKey; //VARIABLE FOR USED/GENERATED KEY - unsigned long unusedKeySize; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY - unsigned long repeatedKeySize; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unusedKeySize) - unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs - enum WHY2_EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE + char *output_text; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT + char *used_key; //VARIABLE FOR USED/GENERATED KEY + unsigned long unused_key_size; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY + unsigned long repeated_key_size; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unused_key_size) + unsigned long elapsed_time; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs + enum WHY2_EXIT_CODES exit_code; //VARIABLE FOR EXIT CODE } why2_output_flags; //NOTE: Variables were moved to 'flags.c' to force y'all using getters @@ -76,7 +76,7 @@ char why2_get_encryption_separator(void); unsigned long why2_get_key_length(void); why2_input_flags why2_get_default_flags(void); //THIS GENERATES why2_input_flags WITH DEFAULT VALUES why2_input_flags why2_get_flags(void); //RETURNS USED FLAGS -why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags +why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags why2_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION why2_bool why2_get_flags_changed(void); char *why2_get_memory_identifier(void); //RETURNS STRING USED IN LINKED LIST (IN memory.c) FOR IDENTIFYING NODES WHEN RUNNING GARBAGE COLLECTOR diff --git a/include/logger/flags.h b/include/logger/flags.h index dfae7a0..c90d3c1 100644 --- a/include/logger/flags.h +++ b/include/logger/flags.h @@ -49,7 +49,7 @@ const enum WHY2_LOGGER_EXIT_CODES //exit codes you fucking idiot (2#) typedef struct { int file; - char *fileName; + char *filename; } why2_log_file; typedef struct @@ -59,7 +59,7 @@ typedef struct typedef struct { - char **decryptedText; + char **decrypted_text; unsigned long length; } why2_decrypted_output; diff --git a/include/misc.h b/include/misc.h index ce36aa0..26c1ffb 100644 --- a/include/misc.h +++ b/include/misc.h @@ -30,8 +30,8 @@ enum WHY2_EXIT_CODES why2_check_version(void); //THIS FUNCTION CHECKS IF LATEST enum WHY2_EXIT_CODES why2_check_key(char *key); //CHECKS IF KEY IS VALID enum WHY2_EXIT_CODES why2_check_text(char *text); //CHECKS IF TEXT IS VALID unsigned long why2_count_int_length(int number); //RETURNS LENGTH OF number -unsigned long why2_count_unused_key_size(char *text, char *key); //COUNT unusedKeySize -unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeatedKeySize +unsigned long why2_count_unused_key_size(char *text, char *key); //COUNT unused_key_size +unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeated_key_size unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS #endif diff --git a/src/core/app/main.c b/src/core/app/main.c index ea69eb9..d878c43 100644 --- a/src/core/app/main.c +++ b/src/core/app/main.c @@ -39,7 +39,7 @@ int main(void) "If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \b\n" "Thank you so much for supporting this project!\n" - , WHY2_TEXT_TO_ENCRYPT, encryptedText.outputText + , WHY2_TEXT_TO_ENCRYPT, encryptedText.output_text ); //DEALLOCATION diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index c42a7f5..8fc62f5 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -67,12 +67,12 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew) int *textKeyChain; char *key = why2_strdup(keyNew); //COPY keyNew TO key int *encryptedTextKeyChain; - char *usedText = why2_strdup(text); //COPY text TO usedText + char *used_text = why2_strdup(text); //COPY text TO used_text //GET LENGTH OF returningText AND textKeyChain - for (int i = 0; i < (int) strlen(usedText); i++) + for (int i = 0; i < (int) strlen(used_text); i++) { - if (usedText[i] == why2_get_encryption_separator()) numberBuffer++; + if (used_text[i] == why2_get_encryption_separator()) numberBuffer++; } //SET LENGTH (numberBuffer) @@ -90,9 +90,9 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew) numberBuffer = 0; //GET LENGTH OF EACH CHARACTER - for (int j = 0; j < (int) strlen(usedText); j++) + for (int j = 0; j < (int) strlen(used_text); j++) { - if (usedText[j] == why2_get_encryption_separator()) break; + if (used_text[j] == why2_get_encryption_separator()) break; numberBuffer++; } @@ -106,16 +106,16 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew) } //LOAD textBuffer - for (int j = 0; j < (int) strlen(usedText); j++) + for (int j = 0; j < (int) strlen(used_text); j++) { - textBuffer[j] = usedText[j]; + textBuffer[j] = used_text[j]; if (numberBuffer == j) break; } encryptedTextKeyChain[i] = atoi(textBuffer); - usedText += numberBuffer + 1; + used_text += numberBuffer + 1; usedTextDeallocationBuffer += numberBuffer + 1; } @@ -149,7 +149,7 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew) why2_free(textKeyChain); why2_free(encryptedTextKeyChain); why2_free(textBuffer); - why2_free(usedText - usedTextDeallocationBuffer); + why2_free(used_text - usedTextDeallocationBuffer); return output; } diff --git a/src/core/lib/flags.c b/src/core/lib/flags.c index a43571e..15e3a90 100644 --- a/src/core/lib/flags.c +++ b/src/core/lib/flags.c @@ -112,7 +112,7 @@ why2_input_flags why2_get_flags(void) return flagsAllah; } -why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode) +why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code) { char *emptyText = why2_malloc(1); //TEXT emptyText[0] = '\0'; @@ -124,7 +124,7 @@ why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode) } emptyKey[why2_get_key_length()] = '\0'; - return (why2_output_flags) { emptyText, emptyKey, 0, 0, 0, exitCode }; + return (why2_output_flags) { emptyText, emptyKey, 0, 0, 0, exit_code }; } why2_encryption_operation_cb why2_get_encryption_operation(void) diff --git a/src/core/lib/test/main.c b/src/core/lib/test/main.c index 0e1fe34..336c03e 100644 --- a/src/core/lib/test/main.c +++ b/src/core/lib/test/main.c @@ -34,7 +34,7 @@ int main(void) char *keyBuffer; char *statusBuffer; char *outputBuffer = why2_malloc(1); //THIS IS TEMP ALLOCATION - int exitCode = 0; + int exit_code = 0; unsigned long timeBuffer; FILE *outputStreamBuffer = stdout; @@ -64,9 +64,9 @@ int main(void) //ENCRYPT why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL); - textBuffer = why2_strdup(encrypted.outputText); //GET ENCRYPTED TEXT - keyBuffer = why2_strdup(encrypted.usedKey); //GET KEY - timeBuffer = encrypted.elapsedTime; //GET TIME 1 + textBuffer = why2_strdup(encrypted.output_text); //GET ENCRYPTED TEXT + keyBuffer = why2_strdup(encrypted.used_key); //GET KEY + timeBuffer = encrypted.elapsed_time; //GET TIME 1 //DEALLOCATE BUFFER why2_deallocate_output(encrypted); @@ -74,10 +74,10 @@ int main(void) //DECRYPT encrypted = why2_decrypt_text(textBuffer, keyBuffer); - timeBuffer += encrypted.elapsedTime; //GET TIME 1 + timeBuffer += encrypted.elapsed_time; //GET TIME 1 //COMPARE DIFFERENCE - if (strcmp(encrypted.outputText, WHY2_TEST_TEXT) == 0 && encrypted.exitCode == 0) //WHY2_SUCCESS + if (strcmp(encrypted.output_text, WHY2_TEST_TEXT) == 0 && encrypted.exit_code == 0) //WHY2_SUCCESS { statusBuffer = why2_strdup("successful"); } @@ -85,11 +85,11 @@ int main(void) { statusBuffer = why2_strdup("failed"); - outputBuffer = why2_realloc(outputBuffer, strlen(encrypted.outputText) + 6); - sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.outputText); + outputBuffer = why2_realloc(outputBuffer, strlen(encrypted.output_text) + 6); + sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.output_text); outputStreamBuffer = stderr; - exitCode = 1; + exit_code = 1; } //PRINT OUTPUT @@ -107,7 +107,7 @@ int main(void) "REPEATED KEY: \t\"%lu\"\n" "EXIT CODE: \t\"%d\"\n" - , statusBuffer, WHY2_TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.repeatedKeySize, encrypted.exitCode + , statusBuffer, WHY2_TEST_TEXT, outputBuffer, textBuffer, encrypted.used_key, timeBuffer / 1000, encrypted.unused_key_size, encrypted.repeated_key_size, encrypted.exit_code ); //DEALLOCATION @@ -117,5 +117,5 @@ int main(void) why2_free(outputBuffer); why2_deallocate_output(encrypted); - return exitCode; + return exit_code; } diff --git a/src/core/lib/utils/misc.c b/src/core/lib/utils/misc.c index d902dc0..3f0984d 100644 --- a/src/core/lib/utils/misc.c +++ b/src/core/lib/utils/misc.c @@ -90,7 +90,7 @@ char *replaceWord(char *string, char *old, char *new) //CODE FROM: https://www.g enum WHY2_EXIT_CODES why2_check_version(void) { - if (why2_get_flags().noCheck) return WHY2_SUCCESS; + if (why2_get_flags().no_check) return WHY2_SUCCESS; why2_set_memory_identifier("core_version_check"); @@ -119,13 +119,13 @@ enum WHY2_EXIT_CODES why2_check_version(void) if (notFoundBuffer == WHY2_NOT_FOUND_TRIES) { - if (!why2_get_flags().noOutput) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME); + if (!why2_get_flags().no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME); why2_clean_memory("core_version_check"); return WHY2_DOWNLOAD_FAILED; } - if (!why2_get_flags().noOutput) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, notFoundBuffer); + if (!why2_get_flags().no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, notFoundBuffer); sleep(1); } @@ -152,7 +152,7 @@ enum WHY2_EXIT_CODES why2_check_version(void) //CHECK FOR TEXT IN buffer if (strcmp(buffer, "") == 0) { - if (!why2_get_flags().noOutput) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n"); + if (!why2_get_flags().no_output) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n"); //WAIT FOR 5 SECONDS sleep(5); @@ -177,7 +177,7 @@ enum WHY2_EXIT_CODES why2_check_version(void) //CHECK FOR ROOT PERMISSIONS if (getuid() != 0) { - if (!why2_get_flags().noOutput) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); + if (!why2_get_flags().no_output) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); why2_clean_memory("core_version_check"); return WHY2_WHY2_UPDATE_FAILED; @@ -185,12 +185,12 @@ enum WHY2_EXIT_CODES why2_check_version(void) //VARIABLES git_repository *repo = NULL; - int exitCode; + int exit_code; char *installCommand; int installCode; //MESSAGE - if (!why2_get_flags().noOutput) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n"); + if (!why2_get_flags().no_output) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n"); //CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'WHY2_UPDATE_NAME' if (access(WHY2_UPDATE_NAME, F_OK) == 0) @@ -200,14 +200,14 @@ enum WHY2_EXIT_CODES why2_check_version(void) git_libgit2_init(); //START GIT2 - exitCode = git_clone(&repo, WHY2_UPDATE_URL, WHY2_UPDATE_NAME, NULL); //CLONE + exit_code = git_clone(&repo, WHY2_UPDATE_URL, WHY2_UPDATE_NAME, NULL); //CLONE git_libgit2_shutdown(); //STOP GIT2 //CHECK FOR ERRORS - if (exitCode != 0) + if (exit_code != 0) { - if (!why2_get_flags().noOutput) fprintf(stderr, "Updating failed! (cloning)\n"); + if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (cloning)\n"); why2_clean_memory("core_version_check"); return WHY2_WHY2_UPDATE_FAILED; @@ -226,7 +226,7 @@ enum WHY2_EXIT_CODES why2_check_version(void) //CHECK FOR ERRORS if (installCode != 0) { - if (!why2_get_flags().noOutput) fprintf(stderr, "Updating failed! (installing)\n"); + if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (installing)\n"); why2_clean_memory("core_version_check"); return WHY2_WHY2_UPDATE_FAILED; @@ -257,7 +257,7 @@ enum WHY2_EXIT_CODES why2_check_version(void) //versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT) if (versionsIndex == -1) { - if (!why2_get_flags().noOutput) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION); + if (!why2_get_flags().no_output) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION); goto deallocation; } @@ -265,7 +265,7 @@ enum WHY2_EXIT_CODES why2_check_version(void) //COUNT versionsBuffer versionsBuffer = json_object_array_length(deprecated) - versionsIndex; - if (!why2_get_flags().noOutput) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, WHY2_VERSION, json_object_get_string(active)); + if (!why2_get_flags().no_output) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, WHY2_VERSION, json_object_get_string(active)); //WAIT FOR 5 SECONDS sleep(5); @@ -320,23 +320,23 @@ void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChain void why2_deallocate_output(why2_output_flags flags) { - why2_free(flags.outputText); - why2_free(flags.usedKey); + why2_free(flags.output_text); + why2_free(flags.used_key); - flags.elapsedTime = 0; - flags.exitCode = WHY2_SUCCESS; - flags.repeatedKeySize = 0; - flags.unusedKeySize = 0; + flags.elapsed_time = 0; + flags.exit_code = WHY2_SUCCESS; + flags.repeated_key_size = 0; + flags.unused_key_size = 0; - flags.outputText = NULL; - flags.usedKey = NULL; + flags.output_text = NULL; + flags.used_key = NULL; } enum WHY2_EXIT_CODES why2_check_key(char *key) { if (strlen(key) < why2_get_key_length()) { - if (!why2_get_flags().noOutput) fprintf(stderr, "Key must be at least %lu characters long!\n", why2_get_key_length()); + if (!why2_get_flags().no_output) fprintf(stderr, "Key must be at least %lu characters long!\n", why2_get_key_length()); return WHY2_INVALID_KEY; } @@ -347,7 +347,7 @@ enum WHY2_EXIT_CODES why2_check_text(char *text) { if (strcmp(text, "") == 0) { - if (!why2_get_flags().noOutput) fprintf(stderr, "No text to encrypt!\n"); + if (!why2_get_flags().no_output) fprintf(stderr, "No text to encrypt!\n"); return WHY2_INVALID_TEXT; } diff --git a/src/logger/lib/logger.c b/src/logger/lib/logger.c index fc7e732..346ca77 100644 --- a/src/logger/lib/logger.c +++ b/src/logger/lib/logger.c @@ -128,7 +128,7 @@ void why2_write_log(int loggerFile, char *logMessage) { why2_output_flags encrypted = why2_encrypt_text(logMessageUsed, flags.key); //ENCRYPT - message = why2_strdup(encrypted.outputText); //COPY + message = why2_strdup(encrypted.output_text); //COPY //DEALLOCATION why2_deallocate_output(encrypted); diff --git a/src/logger/lib/test/main.c b/src/logger/lib/test/main.c index ede4cb5..1cc898d 100644 --- a/src/logger/lib/test/main.c +++ b/src/logger/lib/test/main.c @@ -26,17 +26,17 @@ int main(void) { //VARIABLES why2_log_file logger = why2_init_logger(WHY2_WRITE_DIR); //INITIALIZE LOGGER FILE - char *usedKey = why2_malloc(why2_get_key_length() + 1); + char *used_key = why2_malloc(why2_get_key_length() + 1); why2_decrypted_output decrypted; - int exitCode = 0; + int exit_code = 0; //GENERATE KEY - why2_generate_key(usedKey, why2_get_key_length()); + why2_generate_key(used_key, why2_get_key_length()); //FLAGS why2_log_flags flags = { - usedKey + used_key }; //SET FLAGS @@ -52,9 +52,9 @@ int main(void) //COMPARE OUTPUT if //WHY2_SUCCESS //TODO: Make this smart somehow ( - strcmp(decrypted.decryptedText[0], WHY2_WRITE_MESSAGE_1) == 0 && - strcmp(decrypted.decryptedText[1], WHY2_WRITE_MESSAGE_2) == 0 && - strcmp(decrypted.decryptedText[2], WHY2_WRITE_MESSAGE_3) == 0 + strcmp(decrypted.decrypted_text[0], WHY2_WRITE_MESSAGE_1) == 0 && + strcmp(decrypted.decrypted_text[1], WHY2_WRITE_MESSAGE_2) == 0 && + strcmp(decrypted.decrypted_text[2], WHY2_WRITE_MESSAGE_3) == 0 ) { printf @@ -65,18 +65,18 @@ int main(void) "\t\"%s\"\n" "\t\"%s\"\n", - decrypted.decryptedText[0], decrypted.decryptedText[1], decrypted.decryptedText[2] + decrypted.decrypted_text[0], decrypted.decrypted_text[1], decrypted.decrypted_text[2] ); } else //FAILED { fprintf(stderr, "TEST FAILED!\n"); - exitCode = 1; + exit_code = 1; } //DEALLOCATION - why2_free(usedKey); + why2_free(used_key); why2_deallocate_logger(logger); why2_deallocate_decrypted_output(decrypted); - return exitCode; + return exit_code; } \ No newline at end of file diff --git a/src/logger/lib/utils.c b/src/logger/lib/utils.c index cf0cf9c..4183ef9 100644 --- a/src/logger/lib/utils.c +++ b/src/logger/lib/utils.c @@ -32,9 +32,9 @@ along with this program. If not, see . void why2_deallocate_logger(why2_log_file logger) { close(logger.file); - why2_free(logger.fileName); + why2_free(logger.filename); - logger.fileName = NULL; + logger.filename = NULL; logger.file = INVALID_FILE; } @@ -42,11 +42,11 @@ void why2_deallocate_decrypted_output(why2_decrypted_output output) { for (unsigned long i = 0; i < output.length; i++) { - why2_free(output.decryptedText[i]); + why2_free(output.decrypted_text[i]); } output.length = 0; - why2_free(output.decryptedText); + why2_free(output.decrypted_text); } why2_decrypted_output why2_decrypt_logger(why2_log_file logger) @@ -101,7 +101,7 @@ why2_decrypted_output why2_decrypt_logger(why2_log_file logger) { outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT - contentDecrypted[i] = why2_strdup(outputBuffer.outputText); //COPY + contentDecrypted[i] = why2_strdup(outputBuffer.output_text); //COPY why2_deallocate_output(outputBuffer); //DEALLOCATE outputBuffer }