moved checking for valid key to misc

I'm trying to make code variable as much as possible
This commit is contained in:
Václav Šmejkal 2022-05-26 18:35:15 +02:00
parent 39e174a874
commit 073cdd2468
4 changed files with 12 additions and 10 deletions

View File

@ -6,6 +6,7 @@
void checkVersion(inputFlags flags); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED
void generateTextKeyChain(char key[], int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
void deallocateOutput(outputFlags flags); //DEALLOCATES flags
void checkKey(char *key, inputFlags flags); //CHECKS IF KEY IS VALID
int countIntLength(int number); //RETURNS LENGTH OF number
#endif

View File

@ -10,11 +10,7 @@
outputFlags decryptText(char *text, char *key, inputFlags flags)
{
//CHECK FOR INVALID key
if (strlen(key) < getKeyLength())
{
if (!flags.noOutput) fprintf(stderr, "Key must be at least %d characters long!\n", getKeyLength());
exit(INVALID_KEY);
}
checkKey(key, flags);
//REDEFINE keyLength
setKeyLength(strlen(key));

View File

@ -29,11 +29,7 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
if (keyNew != NULL)
{
if (strlen(keyNew) < getKeyLength())
{
if (!flags.noOutput) fprintf(stderr, "Key must be at least %d characters long!\n", getKeyLength());
exit(INVALID_KEY);
}
checkKey(key, flags); //CHECK FOR INVALID key
strcpy(key, keyNew);

View File

@ -168,6 +168,15 @@ void deallocateOutput(outputFlags flags)
free(flags.usedKey);
}
void checkKey(char *key, inputFlags flags)
{
if (strlen(key) < getKeyLength())
{
if (!flags.noOutput) fprintf(stderr, "Key must be at least %d characters long!\n", getKeyLength());
exit(INVALID_KEY);
}
}
int countIntLength(int number)
{
int returning = 1;