From a900289dbf2249b4479a50e0c3a0ac41ff26915f Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Sun, 27 Aug 2023 20:16:37 +0200 Subject: [PATCH] Rename Pass to LoginInfo and move print_usage, get_args to arg_func.h --- Password_manager/include/arg_func.h | 17 +++++ Password_manager/include/func.h | 28 ++------ Password_manager/source/arg_func.cpp | 80 ++++++++++++++++++----- Password_manager/source/func.cpp | 98 +++++++--------------------- 4 files changed, 111 insertions(+), 112 deletions(-) diff --git a/Password_manager/include/arg_func.h b/Password_manager/include/arg_func.h index 09c94fe..ec1d303 100644 --- a/Password_manager/include/arg_func.h +++ b/Password_manager/include/arg_func.h @@ -5,6 +5,23 @@ class Buffer; class Cryptography; #include +enum class Arg +{ + Get, // get password for label + Generate, // generate password for label + List, // list all labels + Delete, // delete password for label + Print_all_p, // print all passwords + Input, // input password for label + Change, // change main password + Show, // show password for label + Error // error +}; + +void print_args(); + +Arg get_args(int argc, char** argv, char** label); + const char* arg_get(Buffer& decrypted_buffer, const char* label); const char* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto); diff --git a/Password_manager/include/func.h b/Password_manager/include/func.h index 43f29d6..67a93a5 100644 --- a/Password_manager/include/func.h +++ b/Password_manager/include/func.h @@ -3,10 +3,10 @@ class Buffer; -struct Pass +struct LoginInfo { uint32_t label; - uint32_t password; + uint32_t password; }; struct Index @@ -15,26 +15,13 @@ struct Index uint32_t offset; }; -enum class Arg -{ - Get, // get password for label - Generate, // generate password for label - List, // list all labels - Delete, // delete password for label - Print_all_p, // print all passwords - Input, // input password for label - Change, // change main password - Show, // show password for label - Error // error -}; +int find_logininfo_in_buffer(Buffer& buffer, const char* label); -int find_password_in_buffer(Buffer& buff, const char* label); +void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass); -void delete_password_from_buffer(Buffer& in, int index_of_pass); +void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* password); -void add_password_to_buffer(Buffer& in, const char* label, const char* password); - -const char* get_password_from_buffer(Buffer& decrypted_buffer, int label); +const char* get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass); void generate_password(std::string& password, int len); @@ -42,6 +29,3 @@ bool save_buffer_to_file(Buffer& buffer); bool load_buffer_from_file(Buffer& buffer); -void print_usage(); - -Arg get_args(int argc, char** argv, char** label); \ No newline at end of file diff --git a/Password_manager/source/arg_func.cpp b/Password_manager/source/arg_func.cpp index 4c6bee8..e346d93 100644 --- a/Password_manager/source/arg_func.cpp +++ b/Password_manager/source/arg_func.cpp @@ -7,15 +7,63 @@ #include "buffer.h" #include "cryptography.h" +void print_args() +{ + printf_s(" Usage:\n\n"); + printf_s(" password_manager.exe [flags]\n\n"); + printf_s(" Flags:\n\n"); + printf_s(" -h \t print this message\n"); + printf_s("