2023-08-26 01:59:55 +02:00

148 lines
3.3 KiB
C++

#include <iostream>
#include <fstream>
#include "win.h"
#include "buffer.h"
#include "cryptography.h"
#include "func.h"
#include "arg_func.h"
#ifdef _DEBUG
int main()
{
Buffer encrypted_buffer;
load_buffer_from_file(&encrypted_buffer);
printf_s("Input main password:");
std::string user_pass = get_passwd();
if (user_pass.empty())
{
printf_s("Error getting password\n");
return 1;
}
Cryptography crypto(user_pass.c_str(), user_pass.size());
Buffer decrypted_buffer;
if (encrypted_buffer.size > 0)
if (!crypto.decrypt(&encrypted_buffer, &decrypted_buffer)) return 1;
Pass* pass = nullptr;
std::string label = "test";
printf_s("\n--arg_generate--------------------------------------------\n");
pass = arg_generate(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
printf_s("Generated Password: %s\n", pass->password);
printf_s("\n--arg_get-------------------------------------------------\n");
pass = arg_get(decrypted_buffer, label.c_str());
printf_s("Password: %s\n", pass->password);
printf_s("\n--arg_list------------------------------------------------\n");
arg_list(decrypted_buffer);
label = "test2";
printf_s("\n--arg_input-----------------------------------------------\n");
pass = arg_input(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
printf_s("Password: %s\n", pass->password);
printf_s("\n--arg_show------------------------------------------------\n");
arg_show(decrypted_buffer, label.c_str());
printf_s("\n--arg_print_all_p-----------------------------------------\n");
arg_print_all_p(decrypted_buffer, user_pass);
printf_s("\n--arg_delete----------------------------------------------\n");
arg_delete(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
label = "test";
arg_delete(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
}
#else
int main(int argc, char** argv)
{
char* label = nullptr;
Arg args = get_args(argc, argv, &label);
if (args == Arg::Error) return 1;
Buffer encrypted_buffer;
if (!load_buffer_from_file(&encrypted_buffer))
if (!(args == Arg::Generate || args == Arg::Input)) {
printf_s("No passwords, try generating password\n");
return 1;
}
printf_s("Input main password:");
std::string user_pass = get_user_password();
if (user_pass.empty())
{
printf_s("Error getting password\n");
return 1;
}
Cryptography crypto(user_pass.c_str(), user_pass.size());
Buffer decrypted_buffer;
if (encrypted_buffer.size > 0)
if (!crypto.decrypt(&encrypted_buffer, &decrypted_buffer)) return 1;
Pass* pass = nullptr;
switch (args)
{
case Arg::Get:
pass = arg_get(decrypted_buffer, label);
break;
case Arg::Generate:
pass = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto);
break;
case Arg::List:
arg_list(decrypted_buffer);
break;
case Arg::Delete:
arg_delete(decrypted_buffer, encrypted_buffer, label, crypto);
break;
case Arg::Print_all_p:
arg_print_all_p(decrypted_buffer, user_pass);
break;
case Arg::Input:
pass = arg_input(decrypted_buffer, encrypted_buffer, label, crypto);
break;
case Arg::Change:
arg_change(decrypted_buffer, encrypted_buffer, user_pass, crypto);
case Arg::Show:
arg_show(decrypted_buffer, label);
break;
}
if (!pass) return 1;
printf_s("Password copied to clipboard\n");
put_data_on_clipboard(pass->password);
}
#endif // _DEBUG