renamed all 'public' identificators to snake_case

I mean the identificators user gets in contact with
This commit is contained in:
Václav Šmejkal 2023-02-03 17:03:46 +01:00
parent 84a1f4ec8b
commit bbb09428d1
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
11 changed files with 76 additions and 76 deletions

View File

@ -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 int (*why2_encryption_operation_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK
typedef struct typedef struct
{ {
why2_bool noCheck; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK why2_bool no_check; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK
why2_bool noOutput; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING 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_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED
} why2_input_flags; } why2_input_flags;
typedef struct typedef struct
{ {
char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *output_text; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT
char *usedKey; //VARIABLE FOR USED/GENERATED KEY char *used_key; //VARIABLE FOR USED/GENERATED KEY
unsigned long unusedKeySize; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY unsigned long unused_key_size; //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 repeated_key_size; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unused_key_size)
unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs unsigned long elapsed_time; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs
enum WHY2_EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE enum WHY2_EXIT_CODES exit_code; //VARIABLE FOR EXIT CODE
} why2_output_flags; } why2_output_flags;
//NOTE: Variables were moved to 'flags.c' to force y'all using getters //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); 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_default_flags(void); //THIS GENERATES why2_input_flags WITH DEFAULT VALUES
why2_input_flags why2_get_flags(void); //RETURNS USED FLAGS 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_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION
why2_bool why2_get_flags_changed(void); 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 char *why2_get_memory_identifier(void); //RETURNS STRING USED IN LINKED LIST (IN memory.c) FOR IDENTIFYING NODES WHEN RUNNING GARBAGE COLLECTOR

View File

@ -49,7 +49,7 @@ const enum WHY2_LOGGER_EXIT_CODES //exit codes you fucking idiot (2#)
typedef struct typedef struct
{ {
int file; int file;
char *fileName; char *filename;
} why2_log_file; } why2_log_file;
typedef struct typedef struct
@ -59,7 +59,7 @@ typedef struct
typedef struct typedef struct
{ {
char **decryptedText; char **decrypted_text;
unsigned long length; unsigned long length;
} why2_decrypted_output; } why2_decrypted_output;

View File

@ -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_key(char *key); //CHECKS IF KEY IS VALID
enum WHY2_EXIT_CODES why2_check_text(char *text); //CHECKS IF TEXT 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_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_unused_key_size(char *text, char *key); //COUNT unused_key_size
unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeatedKeySize 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 unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS
#endif #endif

View File

@ -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" "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" "Thank you so much for supporting this project!\n"
, WHY2_TEXT_TO_ENCRYPT, encryptedText.outputText , WHY2_TEXT_TO_ENCRYPT, encryptedText.output_text
); );
//DEALLOCATION //DEALLOCATION

View File

@ -67,12 +67,12 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
int *textKeyChain; int *textKeyChain;
char *key = why2_strdup(keyNew); //COPY keyNew TO key char *key = why2_strdup(keyNew); //COPY keyNew TO key
int *encryptedTextKeyChain; 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 //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) //SET LENGTH (numberBuffer)
@ -90,9 +90,9 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
numberBuffer = 0; numberBuffer = 0;
//GET LENGTH OF EACH CHARACTER //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++; numberBuffer++;
} }
@ -106,16 +106,16 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
} }
//LOAD textBuffer //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; if (numberBuffer == j) break;
} }
encryptedTextKeyChain[i] = atoi(textBuffer); encryptedTextKeyChain[i] = atoi(textBuffer);
usedText += numberBuffer + 1; used_text += numberBuffer + 1;
usedTextDeallocationBuffer += numberBuffer + 1; usedTextDeallocationBuffer += numberBuffer + 1;
} }
@ -149,7 +149,7 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
why2_free(textKeyChain); why2_free(textKeyChain);
why2_free(encryptedTextKeyChain); why2_free(encryptedTextKeyChain);
why2_free(textBuffer); why2_free(textBuffer);
why2_free(usedText - usedTextDeallocationBuffer); why2_free(used_text - usedTextDeallocationBuffer);
return output; return output;
} }

View File

@ -112,7 +112,7 @@ why2_input_flags why2_get_flags(void)
return flagsAllah; 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 char *emptyText = why2_malloc(1); //TEXT
emptyText[0] = '\0'; emptyText[0] = '\0';
@ -124,7 +124,7 @@ why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode)
} }
emptyKey[why2_get_key_length()] = '\0'; 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) why2_encryption_operation_cb why2_get_encryption_operation(void)

View File

@ -34,7 +34,7 @@ int main(void)
char *keyBuffer; char *keyBuffer;
char *statusBuffer; char *statusBuffer;
char *outputBuffer = why2_malloc(1); //THIS IS TEMP ALLOCATION char *outputBuffer = why2_malloc(1); //THIS IS TEMP ALLOCATION
int exitCode = 0; int exit_code = 0;
unsigned long timeBuffer; unsigned long timeBuffer;
FILE *outputStreamBuffer = stdout; FILE *outputStreamBuffer = stdout;
@ -64,9 +64,9 @@ int main(void)
//ENCRYPT //ENCRYPT
why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL); why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL);
textBuffer = why2_strdup(encrypted.outputText); //GET ENCRYPTED TEXT textBuffer = why2_strdup(encrypted.output_text); //GET ENCRYPTED TEXT
keyBuffer = why2_strdup(encrypted.usedKey); //GET KEY keyBuffer = why2_strdup(encrypted.used_key); //GET KEY
timeBuffer = encrypted.elapsedTime; //GET TIME 1 timeBuffer = encrypted.elapsed_time; //GET TIME 1
//DEALLOCATE BUFFER //DEALLOCATE BUFFER
why2_deallocate_output(encrypted); why2_deallocate_output(encrypted);
@ -74,10 +74,10 @@ int main(void)
//DECRYPT //DECRYPT
encrypted = why2_decrypt_text(textBuffer, keyBuffer); encrypted = why2_decrypt_text(textBuffer, keyBuffer);
timeBuffer += encrypted.elapsedTime; //GET TIME 1 timeBuffer += encrypted.elapsed_time; //GET TIME 1
//COMPARE DIFFERENCE //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"); statusBuffer = why2_strdup("successful");
} }
@ -85,11 +85,11 @@ int main(void)
{ {
statusBuffer = why2_strdup("failed"); statusBuffer = why2_strdup("failed");
outputBuffer = why2_realloc(outputBuffer, strlen(encrypted.outputText) + 6); outputBuffer = why2_realloc(outputBuffer, strlen(encrypted.output_text) + 6);
sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.outputText); sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.output_text);
outputStreamBuffer = stderr; outputStreamBuffer = stderr;
exitCode = 1; exit_code = 1;
} }
//PRINT OUTPUT //PRINT OUTPUT
@ -107,7 +107,7 @@ int main(void)
"REPEATED KEY: \t\"%lu\"\n" "REPEATED KEY: \t\"%lu\"\n"
"EXIT CODE: \t\"%d\"\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 //DEALLOCATION
@ -117,5 +117,5 @@ int main(void)
why2_free(outputBuffer); why2_free(outputBuffer);
why2_deallocate_output(encrypted); why2_deallocate_output(encrypted);
return exitCode; return exit_code;
} }

View File

@ -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) 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"); 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 (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"); why2_clean_memory("core_version_check");
return WHY2_DOWNLOAD_FAILED; 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); sleep(1);
} }
@ -152,7 +152,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CHECK FOR TEXT IN buffer //CHECK FOR TEXT IN buffer
if (strcmp(buffer, "") == 0) 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 //WAIT FOR 5 SECONDS
sleep(5); sleep(5);
@ -177,7 +177,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CHECK FOR ROOT PERMISSIONS //CHECK FOR ROOT PERMISSIONS
if (getuid() != 0) 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"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; return WHY2_WHY2_UPDATE_FAILED;
@ -185,12 +185,12 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//VARIABLES //VARIABLES
git_repository *repo = NULL; git_repository *repo = NULL;
int exitCode; int exit_code;
char *installCommand; char *installCommand;
int installCode; int installCode;
//MESSAGE //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' //CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'WHY2_UPDATE_NAME'
if (access(WHY2_UPDATE_NAME, F_OK) == 0) 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 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 git_libgit2_shutdown(); //STOP GIT2
//CHECK FOR ERRORS //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"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; return WHY2_WHY2_UPDATE_FAILED;
@ -226,7 +226,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CHECK FOR ERRORS //CHECK FOR ERRORS
if (installCode != 0) 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"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; 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) //versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT)
if (versionsIndex == -1) 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; goto deallocation;
} }
@ -265,7 +265,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//COUNT versionsBuffer //COUNT versionsBuffer
versionsBuffer = json_object_array_length(deprecated) - versionsIndex; 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 //WAIT FOR 5 SECONDS
sleep(5); 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) void why2_deallocate_output(why2_output_flags flags)
{ {
why2_free(flags.outputText); why2_free(flags.output_text);
why2_free(flags.usedKey); why2_free(flags.used_key);
flags.elapsedTime = 0; flags.elapsed_time = 0;
flags.exitCode = WHY2_SUCCESS; flags.exit_code = WHY2_SUCCESS;
flags.repeatedKeySize = 0; flags.repeated_key_size = 0;
flags.unusedKeySize = 0; flags.unused_key_size = 0;
flags.outputText = NULL; flags.output_text = NULL;
flags.usedKey = NULL; flags.used_key = NULL;
} }
enum WHY2_EXIT_CODES why2_check_key(char *key) enum WHY2_EXIT_CODES why2_check_key(char *key)
{ {
if (strlen(key) < why2_get_key_length()) 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; return WHY2_INVALID_KEY;
} }
@ -347,7 +347,7 @@ enum WHY2_EXIT_CODES why2_check_text(char *text)
{ {
if (strcmp(text, "") == 0) 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; return WHY2_INVALID_TEXT;
} }

View File

@ -128,7 +128,7 @@ void why2_write_log(int loggerFile, char *logMessage)
{ {
why2_output_flags encrypted = why2_encrypt_text(logMessageUsed, flags.key); //ENCRYPT 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 //DEALLOCATION
why2_deallocate_output(encrypted); why2_deallocate_output(encrypted);

View File

@ -26,17 +26,17 @@ int main(void)
{ {
//VARIABLES //VARIABLES
why2_log_file logger = why2_init_logger(WHY2_WRITE_DIR); //INITIALIZE LOGGER FILE 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; why2_decrypted_output decrypted;
int exitCode = 0; int exit_code = 0;
//GENERATE KEY //GENERATE KEY
why2_generate_key(usedKey, why2_get_key_length()); why2_generate_key(used_key, why2_get_key_length());
//FLAGS //FLAGS
why2_log_flags flags = why2_log_flags flags =
{ {
usedKey used_key
}; };
//SET FLAGS //SET FLAGS
@ -52,9 +52,9 @@ int main(void)
//COMPARE OUTPUT //COMPARE OUTPUT
if //WHY2_SUCCESS //TODO: Make this smart somehow if //WHY2_SUCCESS //TODO: Make this smart somehow
( (
strcmp(decrypted.decryptedText[0], WHY2_WRITE_MESSAGE_1) == 0 && strcmp(decrypted.decrypted_text[0], WHY2_WRITE_MESSAGE_1) == 0 &&
strcmp(decrypted.decryptedText[1], WHY2_WRITE_MESSAGE_2) == 0 && strcmp(decrypted.decrypted_text[1], WHY2_WRITE_MESSAGE_2) == 0 &&
strcmp(decrypted.decryptedText[2], WHY2_WRITE_MESSAGE_3) == 0 strcmp(decrypted.decrypted_text[2], WHY2_WRITE_MESSAGE_3) == 0
) )
{ {
printf printf
@ -65,18 +65,18 @@ int main(void)
"\t\"%s\"\n" "\t\"%s\"\n"
"\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 } else //FAILED
{ {
fprintf(stderr, "TEST FAILED!\n"); fprintf(stderr, "TEST FAILED!\n");
exitCode = 1; exit_code = 1;
} }
//DEALLOCATION //DEALLOCATION
why2_free(usedKey); why2_free(used_key);
why2_deallocate_logger(logger); why2_deallocate_logger(logger);
why2_deallocate_decrypted_output(decrypted); why2_deallocate_decrypted_output(decrypted);
return exitCode; return exit_code;
} }

View File

@ -32,9 +32,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
void why2_deallocate_logger(why2_log_file logger) void why2_deallocate_logger(why2_log_file logger)
{ {
close(logger.file); close(logger.file);
why2_free(logger.fileName); why2_free(logger.filename);
logger.fileName = NULL; logger.filename = NULL;
logger.file = INVALID_FILE; 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++) for (unsigned long i = 0; i < output.length; i++)
{ {
why2_free(output.decryptedText[i]); why2_free(output.decrypted_text[i]);
} }
output.length = 0; output.length = 0;
why2_free(output.decryptedText); why2_free(output.decrypted_text);
} }
why2_decrypted_output why2_decrypt_logger(why2_log_file logger) 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 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 why2_deallocate_output(outputBuffer); //DEALLOCATE outputBuffer
} }