|
3 | 3 | // header guarding |
4 | 4 | #ifndef __SYSTEM_ENCRYPTION_FF__ |
5 | 5 | #include "SysEnc.hpp" |
6 | | - |
| 6 | + |
7 | 7 | // double check for namespace macro definition validation |
8 | 8 | #if defined(__SYSTEM_ENCRYPTION_FF__) |
9 | 9 |
|
@@ -436,27 +436,75 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg, |
436 | 436 | return true; |
437 | 437 | }; |
438 | 438 |
|
| 439 | +/** |
| 440 | + * Create a test directory with a list of files from test_files list, test_files entries must only contain file name without path, |
| 441 | + * and the dir_path value must be an absolute path to the test directory to create. |
| 442 | + * For example, dir_path = "/path/to/dir/test" and test_file = {"file1.txt", "file2.txt", ...} |
| 443 | + * @param const StringView_t& the directory path |
| 444 | + * @param const std::initializer_list<String_t> list of files to create into dir_path |
| 445 | + * @returns const bool if test directory was created or not |
| 446 | +*/ |
| 447 | +[[maybe_unused, nodiscard]] const System::String_t System::Crypto::CreateTestDirectory(const StringView_t &dir_path, const std::initializer_list<String_t> test_files) { |
| 448 | + String_t rVal; |
| 449 | + if (dir_path.empty()) |
| 450 | + { |
| 451 | + LogWarning("Test Directory is empty!\n"); |
| 452 | + return rVal; |
| 453 | + } |
| 454 | + if(test_files.size() == 0){ |
| 455 | + LogWarning("File list is empty, no files will be created..\n"); |
| 456 | + } |
| 457 | + if(DirectoryExists(dir_path)){ |
| 458 | + LogWarning("Directory already exists!\n"); |
| 459 | + return rVal; |
| 460 | + } |
| 461 | + std::filesystem::create_directories(std::move(dir_path.data())) || std::filesystem::create_directory(std::move(dir_path.data())); |
| 462 | + if(DirectoryExists(dir_path.data())){ |
| 463 | + for(const String_t &new_file: test_files){ |
| 464 | + if(new_file.compare(".") == 0 || new_file.compare("..") == 0) |
| 465 | + continue; |
| 466 | + |
| 467 | + String_t entry_id = dir_path.data(); |
| 468 | + entry_id += PATH_SEPARATOR; |
| 469 | + entry_id += std::move(new_file.c_str()); |
| 470 | + LogMessage("Creating test file <", entry_id, ">...\n"); |
| 471 | + std::ofstream createFile(entry_id.c_str()); |
| 472 | + createFile << "Something in this file"; |
| 473 | + createFile.close(); |
| 474 | + if(FileExists(std::move(entry_id.c_str()))){ |
| 475 | + LogMessage("File <", entry_id.c_str(), "> created!\n"); |
| 476 | + } |
| 477 | + } |
| 478 | + rVal = dir_path; |
| 479 | + } |
| 480 | + else |
| 481 | + { |
| 482 | + LogError("Cannot find directory!"); |
| 483 | + } |
| 484 | + return rVal; |
| 485 | +}; |
| 486 | + |
439 | 487 | /* Suppliers *\ |
440 | 488 | \*****************************************************************************/ |
441 | 489 |
|
442 | 490 | [[maybe_unused]] void System::Crypto::SetRecoveryMode(void) noexcept |
443 | 491 | { |
444 | | - std::cout << "Veryfing Registry Key Address...\n"; |
| 492 | + LogMessage("Veryfing Registry Key Address...\n"); |
445 | 493 | if (!RegistryPathExists()) [[likely]] |
446 | 494 | { |
447 | | - std::cout << "Registry Path Not Found\n"; |
| 495 | + LogMessage("Registry Path Not Found\n"); |
448 | 496 | if (!RegistryPathCreate()) [[unlikely]] |
449 | 497 | { |
450 | | - std::cout << "Cannot create Registry Path\n"; |
| 498 | + LogMessage("Cannot create Registry Path\n"); |
451 | 499 | return; |
452 | 500 | } |
453 | | - std::cout << "Registry Path Created\n"; |
| 501 | + LogMessage("Registry Path Created\n"); |
454 | 502 | } |
455 | 503 |
|
456 | 504 | String_t rec_mode; |
457 | 505 | std::cout << "Choose Decryption Recovery Mode:\n1) Supply Your Own Recovery key\n2) Generate Secure Keys\n"; |
458 | 506 | SetRecoveryMode: |
459 | | - std::cout << "Select One [1/2] : "; |
| 507 | + std::cout<<"Select One [1/2] : "; |
460 | 508 | std::cin >> rec_mode; |
461 | 509 | if (rec_mode.compare("1") == 0) [[likely]] |
462 | 510 | { |
@@ -526,7 +574,7 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg, |
526 | 574 | } |
527 | 575 | else if (!DirectoryExists(target_path) && !FileExists(target_path)) [[unlikely]] |
528 | 576 | { |
529 | | - std::cout << "Supplied Path not found!\n"; |
| 577 | + std::cout << "Supplied Path not found!\n"; |
530 | 578 | goto TargetPathSupply; |
531 | 579 | } |
532 | 580 |
|
@@ -710,7 +758,7 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg, |
710 | 758 | const String_t key_validate = ReadFile(std::move(ReadFile(SECURE_OWN_KEY_REF).c_str())); |
711 | 759 | if (!key_validate.empty()) [[likely]] |
712 | 760 | { |
713 | | - std::cout << "KEY SIZE: " << key_validate.size() << '\n'; |
| 761 | + LogMessage("KEY SIZE: ", key_validate.size(), '\n'); |
714 | 762 | if (key_validate.size() == CryptoPP::AES::DEFAULT_KEYLENGTH) [[likely]] |
715 | 763 | { |
716 | 764 | return true; |
@@ -760,8 +808,6 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg, |
760 | 808 | else if (StringView_t(argv[_j]).compare("--silent") == 0) |
761 | 809 | exeMode ^= ExecuteMode::VERBOSE; |
762 | 810 | } |
763 | | - std::cout << "USING EASED ? " << (exeMode & ExecuteMode::EASED ? "true":"false") << "\n"; |
764 | | - std::cout << "USING VERBOSE ? " << (exeMode & ExecuteMode::VERBOSE ? "true":"false") << "\n"; |
765 | 811 | } |
766 | 812 | } |
767 | 813 | catch (const std::exception &_e) |
|
0 commit comments