Compare commits

..

8 Commits

Author SHA1 Message Date
17a73d9157
implemented anon flags in logger
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 1m45s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 3m42s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m41s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m11s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m24s
2025-01-13 19:55:54 +01:00
520f8bce34
created anon fns for core-flags changed vars
calling sets flag without changing flag_changed variable
2025-01-13 19:54:44 +01:00
9e5016feb7
defined why2_get_padding_changed
and guess what it returns
2025-01-13 19:46:00 +01:00
59d6252fe3
declared why2_get_padding_changed fn 2025-01-13 19:45:19 +01:00
64f54fadce
added padding_changed to core-flags 2025-01-13 19:44:39 +01:00
4451b848f7
changed weird variable names in core-flags 2025-01-13 19:42:05 +01:00
917b466b11
replacing \n with space in logger
instead of null-term and breaking the string
2025-01-13 19:22:53 +01:00
0fe3f47752
added why2_set_padding fn
sets padding without messing with flags
2025-01-12 13:12:50 +01:00
4 changed files with 57 additions and 11 deletions

View File

@ -104,15 +104,20 @@ why2_input_flags why2_get_flags(void); //RETURNS USED 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);
why2_bool why2_get_padding_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_default_memory_identifier(void);
//SETTERS
void why2_set_encryption_separator(char encryption_separator_new);
void why2_set_key_length(int keyLengthNew);
void why2_set_flags(why2_input_flags newFlags); //.... whatcha think?
void why2_set_flags(why2_input_flags new_flags); //.... whatcha think?
void __why2_set_flags_anon(why2_input_flags new_flags); //DO NOT CHANGE flags_changed ON USAGE
void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation); //are you that dumb?
void why2_set_memory_identifier(char *new_memory_identifier);
void why2_set_padding(unsigned long padding); //SET PADDING RATE WITHOUT REWRITING INPUT FLAGS
void __why2_set_padding_anon(unsigned long padding);
void why2_reset_memory_identifier(void); //hmmm, what could reset mean.... huh
#ifdef __cplusplus

View File

@ -33,9 +33,10 @@ int encryptionOperation(int text, int encryptedText);
//VARIABLES
char encryption_separator = '.'; //NOPE > DO NOT TOUCH THIS, USE why2_set_encryption_separator instead <
unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE why2_set_key_length instead <
why2_input_flags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS
why2_input_flags used_flags = DEFAULT_FLAGS; //IT IS CALLED used_flags CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS
why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation;
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
why2_bool flags_changed = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
why2_bool padding_changed = 0; //SAME AS flags_changed BUT FOR PADDING
char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER;
why2_list_t identifier_list = WHY2_LIST_EMPTY;
@ -68,7 +69,7 @@ why2_input_flags why2_get_default_flags(void)
why2_input_flags why2_get_flags(void)
{
return flagsAllah;
return used_flags;
}
why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code)
@ -93,7 +94,12 @@ why2_encryption_operation_cb why2_get_encryption_operation(void)
why2_bool why2_get_flags_changed(void)
{
return flagsChanged;
return flags_changed;
}
why2_bool why2_get_padding_changed(void)
{
return padding_changed;
}
char *why2_get_memory_identifier(void)
@ -126,11 +132,20 @@ void why2_set_key_length(int keyLengthNew)
keyLength = keyLengthNew;
}
void why2_set_flags(why2_input_flags newFlags)
void why2_set_flags(why2_input_flags new_flags)
{
flagsAllah = newFlags;
__why2_set_flags_anon(new_flags);
if (!flagsChanged) flagsChanged = 1;
if (!flags_changed)
{
flags_changed = 1;
padding_changed = 1;
}
}
void __why2_set_flags_anon(why2_input_flags new_flags)
{
used_flags = new_flags;
}
void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation)
@ -145,6 +160,17 @@ void why2_set_memory_identifier(char *new_memory_identifier)
memory_identifier = new_memory_identifier;
}
void why2_set_padding(unsigned long padding)
{
__why2_set_padding_anon(padding);
if (!padding_changed) padding_changed = 1;
}
void __why2_set_padding_anon(unsigned long padding)
{
used_flags.padding = padding;
}
void why2_reset_memory_identifier(void)
{
why2_list_remove_back(&identifier_list);

View File

@ -29,7 +29,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/flags.h>
#include <why2/logger/utils.h>
#include <why2/crypto.h>
#include <why2/encrypter.h>
#include <why2/flags.h>
#include <why2/memory.h>
#include <why2/misc.h>
@ -94,6 +96,9 @@ why2_log_file why2_init_logger(char *directoryPath)
}
}
//SET ENCRYPTER FLAGS
if (!why2_get_flags_changed()) __why2_set_flags_anon((why2_input_flags) { 0, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 64 });
//DEALLOCATION
why2_deallocate(dateBuffer);
why2_deallocate(latestBuffer);
@ -121,7 +126,7 @@ void why2_write_log(int loggerFile, char *logMessage)
char *logMessageUsed = why2_strdup(logMessage);
for (int i = 0; i < (int) strlen(logMessageUsed); i++)
{
if (logMessageUsed[i] == '\n') logMessageUsed[i] = '\0';
if (logMessageUsed[i] == '\n') logMessageUsed[i] = ' ';
}
//VARIABLES
@ -131,8 +136,7 @@ void why2_write_log(int loggerFile, char *logMessage)
struct tm tm = *localtime(&timeL);
why2_log_flags flags = why2_get_log_flags();
//SET ENCRYPTER FLAGS
if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 63 });
if (!why2_get_padding_changed()) __why2_set_padding_anon(WHY2_RECOMMENDED_PADDING_RATE(strlen(logMessageUsed)));
if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED
{

View File

@ -107,6 +107,17 @@ why2_decrypted_output why2_decrypt_logger(why2_log_file logger)
for (int i = 0; i < lines; i++) //DECRYPT content
{
if (!why2_get_padding_changed())
{
printf("A\n");
unsigned long length_buffer = 1;
for (unsigned long j = 0; j < strlen(content[i]); j++)
{
if (content[i][j] == why2_get_encryption_separator()) length_buffer++;
}
__why2_set_padding_anon(length_buffer / 4);
}
outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT
contentDecrypted[i] = why2_strdup(outputBuffer.output_text); //COPY