Skip to content

Commit 5a6d8c5

Browse files
committed
finished factorization
1 parent d08d00a commit 5a6d8c5

File tree

7 files changed

+317
-127
lines changed

7 files changed

+317
-127
lines changed

README.md

Lines changed: 253 additions & 110 deletions
Large diffs are not rendered by default.

include/SysEnc.cpp

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// header guarding
44
#ifndef __SYSTEM_ENCRYPTION_FF__
55
#include "SysEnc.hpp"
6-
6+
77
// double check for namespace macro definition validation
88
#if defined(__SYSTEM_ENCRYPTION_FF__)
99

@@ -436,27 +436,75 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg,
436436
return true;
437437
};
438438

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+
439487
/* Suppliers *\
440488
\*****************************************************************************/
441489

442490
[[maybe_unused]] void System::Crypto::SetRecoveryMode(void) noexcept
443491
{
444-
std::cout << "Veryfing Registry Key Address...\n";
492+
LogMessage("Veryfing Registry Key Address...\n");
445493
if (!RegistryPathExists()) [[likely]]
446494
{
447-
std::cout << "Registry Path Not Found\n";
495+
LogMessage("Registry Path Not Found\n");
448496
if (!RegistryPathCreate()) [[unlikely]]
449497
{
450-
std::cout << "Cannot create Registry Path\n";
498+
LogMessage("Cannot create Registry Path\n");
451499
return;
452500
}
453-
std::cout << "Registry Path Created\n";
501+
LogMessage("Registry Path Created\n");
454502
}
455503

456504
String_t rec_mode;
457505
std::cout << "Choose Decryption Recovery Mode:\n1) Supply Your Own Recovery key\n2) Generate Secure Keys\n";
458506
SetRecoveryMode:
459-
std::cout << "Select One [1/2] : ";
507+
std::cout<<"Select One [1/2] : ";
460508
std::cin >> rec_mode;
461509
if (rec_mode.compare("1") == 0) [[likely]]
462510
{
@@ -526,7 +574,7 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg,
526574
}
527575
else if (!DirectoryExists(target_path) && !FileExists(target_path)) [[unlikely]]
528576
{
529-
std::cout << "Supplied Path not found!\n";
577+
std::cout << "Supplied Path not found!\n";
530578
goto TargetPathSupply;
531579
}
532580

@@ -710,7 +758,7 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg,
710758
const String_t key_validate = ReadFile(std::move(ReadFile(SECURE_OWN_KEY_REF).c_str()));
711759
if (!key_validate.empty()) [[likely]]
712760
{
713-
std::cout << "KEY SIZE: " << key_validate.size() << '\n';
761+
LogMessage("KEY SIZE: ", key_validate.size(), '\n');
714762
if (key_validate.size() == CryptoPP::AES::DEFAULT_KEYLENGTH) [[likely]]
715763
{
716764
return true;
@@ -760,8 +808,6 @@ template <typename mT, typename... tArgs> void System::Crypto::LogError(mT msg,
760808
else if (StringView_t(argv[_j]).compare("--silent") == 0)
761809
exeMode ^= ExecuteMode::VERBOSE;
762810
}
763-
std::cout << "USING EASED ? " << (exeMode & ExecuteMode::EASED ? "true":"false") << "\n";
764-
std::cout << "USING VERBOSE ? " << (exeMode & ExecuteMode::VERBOSE ? "true":"false") << "\n";
765811
}
766812
}
767813
catch (const std::exception &_e)

include/SysEnc.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
typedef long long int int64_t;
66
typedef unsigned long long int uint64_t;
77
#endif
8-
8+
99
// Check if compiler supports char16_t and char32_t
1010
#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L))
1111
typedef unsigned short char16_t;
@@ -320,6 +320,7 @@ class Crypto
320320
[[maybe_unused, nodiscard]] inline static const bool CreateBackup(const StringView_t &target);
321321
[[nodiscard]] static const std::vector<System::String_t> DirectoryAggregation(const StringView_t &target);
322322
[[nodiscard]] static const bool Rename(const System::StringView_t &file_name, const bool byte_plus) __attribute__((hot));
323+
[[maybe_unused, nodiscard]] inline static const String_t CreateTestDirectory(const StringView_t &dir_path, const std::initializer_list<String_t> test_files);
323324

324325
// Supplier Region
325326
[[maybe_unused]] inline static void SetRecoveryMode(void) noexcept;

src/dec

0 Bytes
Binary file not shown.

src/dec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright 2024
44
5-
File: enc.cpp
5+
File: enc.cpp
66
77
Author: NetRay
88

src/enc

9.03 KB
Binary file not shown.

src/enc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright 2024
44
5-
File: enc.cpp
5+
File: enc.cpp
66
77
Author: NetRay
88
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
5151
}
5252

5353
// register/store target
54-
Crypto::RegisterTargetPath(set_target);
54+
Crypto::RegisterTargetPath(std::move(set_target));
5555

5656
// get target
5757
const std::optional<String_t> use_target = Crypto::GetTargetPath();
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
6363
std::cout << "Using Target Path: " << use_target.value() << std::endl;
6464

6565
// Collect Resources
66-
const std::vector<String_t> aggregation_stack = Crypto::DirectoryAggregation(use_target.value());
66+
const std::vector<String_t> aggregation_stack = Crypto::DirectoryAggregation(std::move(use_target.value()));
6767

6868
if (aggregation_stack.empty()) [[unlikely]]
6969
{
@@ -76,15 +76,15 @@ int main(int argc, char **argv)
7676

7777
if (*Crypto::with_backup >= 1)
7878
{
79-
if (!Crypto::CreateBackup(use_target.value())) [[unlikely]]
79+
if (!Crypto::CreateBackup(std::move(use_target.value()))) [[unlikely]]
8080
{
8181
throw std::runtime_error("Backup Operation Failed.. aborting..");
8282
}
8383
std::cout << "Backup Create Successfully!\n";
8484
}
8585

8686
// Prepare Secure Key Block
87-
const std::optional<CryptoPP::SecByteBlock> ParseKey = Crypto::RecoveryKeyIntersect(recovery_key);
87+
const std::optional<CryptoPP::SecByteBlock> ParseKey = Crypto::RecoveryKeyIntersect(std::move(recovery_key));
8888

8989
if (!ParseKey.has_value()) [[unlikely]]
9090
throw std::runtime_error("Error Intersection Recovery Key");

0 commit comments

Comments
 (0)