This commit is contained in:
Nikola Petrov 2023-08-15 16:54:08 +02:00
parent 43fda0a392
commit 6d9404b9b5
6 changed files with 97 additions and 105 deletions

View File

@ -7,7 +7,7 @@ enum class Glob_Result {
SYNTAX_ERROR,
UNMATCHED,
MATCHED,
} ;
};
// https://github.com/tsoding/glob.h
Glob_Result glob(const char* pattern, const char* text);

View File

@ -35,7 +35,7 @@ bool Buffer::resize(size_t new_size)
void Buffer::add(uint8_t* data, size_t data_size)
{
if (taken + data_size > size)
if(!resize(size + data_size)) return;
if (!resize(size + data_size)) return;
memcpy_s(buffer + taken, size - taken, data, data_size);
taken += data_size;

View File

@ -34,7 +34,7 @@ bool Cryptography::encrypt(Buffer* plain, Buffer* encrypted)
if (!ctx) return handleErrors();
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) return handleErrors();
if (1 != EVP_EncryptUpdate(ctx, encrypted->buffer, (int*)& encrypted->taken, plain->buffer, plain->taken)) return handleErrors();
if (1 != EVP_EncryptUpdate(ctx, encrypted->buffer, (int*)&encrypted->taken, plain->buffer, plain->taken)) return handleErrors();
int final_len;
if (1 != EVP_EncryptFinal_ex(ctx, encrypted->buffer + encrypted->taken, &final_len)) return handleErrors();
encrypted->taken += final_len;
@ -54,7 +54,7 @@ bool Cryptography::decrypt(Buffer* encrypted, Buffer* decrypted)
if (!ctx) return handleErrors();
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) return handleErrors();
if (1 != EVP_DecryptUpdate(ctx, decrypted->buffer, (int*) & decrypted->taken, encrypted->buffer, encrypted->taken)) return handleErrors();
if (1 != EVP_DecryptUpdate(ctx, decrypted->buffer, (int*)&decrypted->taken, encrypted->buffer, encrypted->taken)) return handleErrors();
int final_len;
if (1 != EVP_DecryptFinal_ex(ctx, decrypted->buffer + decrypted->taken, &final_len)) return handleErrors();
decrypted->taken += final_len;

View File

@ -41,7 +41,6 @@ bool save_buffer_to_file(Buffer* buffer)
bool load_buffer_from_file(Buffer* buffer)
{
std::ifstream file("passwords.bin", std::ios::binary);
if (!file.is_open()) return false;
@ -116,6 +115,5 @@ Args get_args(int argc, char** argv, char** label) {
return Args::Input;
}
return Args::Error;
}

View File

@ -9,9 +9,7 @@ int main(int argc, char** argv)
{
char* label = nullptr;
Args args = get_args(argc, argv, &label);
if(args == Args::Error) return 1;
if (args == Args::Error) return 1;
Buffer encrypted_buffer;
if (!load_buffer_from_file(&encrypted_buffer))
@ -20,8 +18,6 @@ int main(int argc, char** argv)
return 1;
}
printf_s("Input main password:");
std::string user_pass = get_passwd();
if (user_pass.empty())
@ -36,13 +32,11 @@ int main(int argc, char** argv)
if (encrypted_buffer.size > 0)
if (!crypto.decrypt(&encrypted_buffer, &decrypted_buffer)) return 1;
Pass* pass = nullptr;
Pass new_pass = { 0 };
Pass* passwords = nullptr;
std::string new_string;
switch (args)
{
case Args::Get:
@ -63,7 +57,7 @@ int main(int argc, char** argv)
{
generate_password(new_pass.password);
strcpy_s(new_pass.label, MAX_STRING_SIZE, label);
decrypted_buffer.add((uint8_t*) & new_pass, sizeof(Pass));
decrypted_buffer.add((uint8_t*)&new_pass, sizeof(Pass));
pass = &new_pass;
}