diff --git a/Password_manager/include/arg_func.h b/Password_manager/include/arg_func.h index ec1d303..d9ebc86 100644 --- a/Password_manager/include/arg_func.h +++ b/Password_manager/include/arg_func.h @@ -1,6 +1,6 @@ #pragma once -struct Pass; +struct LoginInfoPointer; class Buffer; class Cryptography; #include @@ -22,9 +22,11 @@ void print_args(); Arg get_args(int argc, char** argv, char** label); -const char* arg_get(Buffer& decrypted_buffer, const char* label); +LoginInfoPointer arg_get(Buffer& decrypted_buffer, const char* label); -const char* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto); +LoginInfoPointer arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto); + +LoginInfoPointer arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto); void arg_list(Buffer& decrypted_buffer); @@ -32,8 +34,6 @@ void arg_delete(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass); -const char* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto); - void arg_change(Buffer& decrypted_buffer, Buffer& encrypted_buffer, std::string& user_pass, Cryptography& crypto); void arg_show(Buffer& decrypted_buffer, const char* label); \ No newline at end of file diff --git a/Password_manager/include/func.h b/Password_manager/include/func.h index 67a93a5..8604a20 100644 --- a/Password_manager/include/func.h +++ b/Password_manager/include/func.h @@ -9,6 +9,14 @@ struct LoginInfo uint32_t password; }; +struct LoginInfoPointer +{ + const char* label; + const char* password; + + LoginInfoPointer() : label(nullptr), password(nullptr) {} +}; + struct Index { uint32_t count; @@ -21,7 +29,7 @@ void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass); void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* password); -const char* get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass); +LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass); void generate_password(std::string& password, int len); diff --git a/Password_manager/source/arg_func.cpp b/Password_manager/source/arg_func.cpp index e346d93..4277f2b 100644 --- a/Password_manager/source/arg_func.cpp +++ b/Password_manager/source/arg_func.cpp @@ -56,17 +56,17 @@ Arg get_args(int argc, char** argv, char** label) { return Arg::Error; } -const char* arg_get(Buffer& decrypted_buffer, const char* label) +LoginInfoPointer arg_get(Buffer& decrypted_buffer, const char* label) { int pass = find_logininfo_in_buffer(decrypted_buffer, label); if (pass < 0) { printf_s("Password not found\n"); - return nullptr; + return LoginInfoPointer(); } return get_logininfo_pointer_from_buffer(decrypted_buffer, pass); } -const char* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto) +LoginInfoPointer arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto) { printf_s("Generating password for %s\n", label); @@ -83,7 +83,7 @@ const char* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, con return get_logininfo_pointer_from_buffer(decrypted_buffer, index->count - 1); } -const char* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto) +LoginInfoPointer arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto) { printf_s("Input password for %s:", label); @@ -91,7 +91,9 @@ const char* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const if (new_string.empty()) { printf_s("error getting password\n"); - return nullptr; + + return LoginInfoPointer(); + } int pass = find_logininfo_in_buffer(decrypted_buffer, label); diff --git a/Password_manager/source/func.cpp b/Password_manager/source/func.cpp index 8655ef1..1d052d3 100644 --- a/Password_manager/source/func.cpp +++ b/Password_manager/source/func.cpp @@ -56,11 +56,14 @@ void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* pass } -const char* get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass) +LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass) { Index* index = (Index*)buffer.buffer; LoginInfo* pass = (LoginInfo*)(buffer.buffer + sizeof(Index)); - return (const char*)buffer.buffer + pass[index_of_pass].password + index->offset; + LoginInfoPointer ret; + ret.label = (const char*)buffer.buffer + pass[index_of_pass].label + index->offset; + ret.password = (const char*)buffer.buffer + pass[index_of_pass].password + index->offset; + return ret; } void generate_password(std::string& password, int len) diff --git a/Password_manager/source/main.cpp b/Password_manager/source/main.cpp index 51894f8..605b243 100644 --- a/Password_manager/source/main.cpp +++ b/Password_manager/source/main.cpp @@ -35,16 +35,16 @@ int main() decrypted_buffer.add_end((uint8_t*)&index, sizeof(Index)); } - const char* pass = nullptr; + LoginInfoPointer login_info; switch (args) { case Arg::Get: - pass = arg_get(decrypted_buffer, label); + login_info = arg_get(decrypted_buffer, label); break; case Arg::Generate: - pass = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto); + login_info = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto); break; case Arg::List: @@ -60,7 +60,7 @@ int main() break; case Arg::Input: - pass = arg_input(decrypted_buffer, encrypted_buffer, label, crypto); + login_info = arg_input(decrypted_buffer, encrypted_buffer, label, crypto); break; case Arg::Change: @@ -72,10 +72,10 @@ int main() break; } - if (!pass) return 0; + if (!login_info.password) return 0; printf_s("Password copied to clipboard\n"); - put_data_on_clipboard(pass); + put_data_on_clipboard(login_info.password); } @@ -114,16 +114,16 @@ int main(int argc, char** argv) decrypted_buffer.add_end((uint8_t*)&index, sizeof(Index)); } - const char* pass = nullptr; + LoginInfoPointer login_info; switch (args) { case Arg::Get: - pass = arg_get(decrypted_buffer, label); + login_info = arg_get(decrypted_buffer, label); break; case Arg::Generate: - pass = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto); + login_info = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto); break; case Arg::List: @@ -139,7 +139,7 @@ int main(int argc, char** argv) break; case Arg::Input: - pass = arg_input(decrypted_buffer, encrypted_buffer, label, crypto); + login_info = arg_input(decrypted_buffer, encrypted_buffer, label, crypto); break; case Arg::Change: @@ -151,10 +151,10 @@ int main(int argc, char** argv) break; } - if (!pass) return 1; + if (!login_info.password) return 1; printf_s("Password copied to clipboard\n"); - put_data_on_clipboard(pass); + put_data_on_clipboard(login_info.password); }