updated build system
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				BlockStorage/repertory/pipeline/head There was a failure building this commit
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	BlockStorage/repertory/pipeline/head There was a failure building this commit
				
			This commit is contained in:
		| @@ -25,9 +25,19 @@ | ||||
|  | ||||
| #include "utils/collection.hpp" | ||||
| #include "utils/encrypting_reader.hpp" | ||||
| #include "utils/hash.hpp" | ||||
| #include "utils/path.hpp" | ||||
|  | ||||
| namespace repertory::utils::encryption { | ||||
| auto kdf_config::to_header() const -> data_buffer { | ||||
|   kdf_config tmp{*this}; | ||||
|   tmp.checksum = boost::endian::native_to_big(tmp.checksum); | ||||
|   tmp.magic = boost::endian::native_to_big(tmp.magic); | ||||
|  | ||||
|   data_buffer ret(size()); | ||||
|   std::memcpy(ret.data(), &tmp, ret.size()); | ||||
|   return ret; | ||||
| } | ||||
|  | ||||
| auto kdf_config::generate_checksum() const -> std::uint64_t { | ||||
|   REPERTORY_USES_FUNCTION_NAME(); | ||||
| @@ -35,18 +45,8 @@ auto kdf_config::generate_checksum() const -> std::uint64_t { | ||||
|   kdf_config tmp = *this; | ||||
|   tmp.checksum = 0; | ||||
|  | ||||
|   auto hdr = tmp.to_header(); | ||||
|  | ||||
|   std::uint64_t ret{0}; | ||||
|   if (crypto_generichash(reinterpret_cast<unsigned char *>(&ret), sizeof(ret), | ||||
|                          hdr.data(), hdr.size(), nullptr, 0) != 0) { | ||||
|     throw utils::error::create_exception(function_name, | ||||
|                                          { | ||||
|                                              "failed to calculate checksum", | ||||
|                                          }); | ||||
|   } | ||||
|  | ||||
|   return ret; | ||||
|   auto hash = utils::hash::create_hash_blake2b_64(tmp.to_header()); | ||||
|   return *reinterpret_cast<std::uint64_t *>(hash.data()); | ||||
| } | ||||
|  | ||||
| void kdf_config::generate_salt() { | ||||
|   | ||||
| @@ -26,6 +26,57 @@ | ||||
| #include "utils/error.hpp" | ||||
|  | ||||
| namespace repertory::utils::hash { | ||||
| auto create_hash_blake2b_32(std::string_view data) -> hash_32_t { | ||||
|   return create_hash_blake2b_t<hash_32_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), data.size()); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_32(std::wstring_view data) -> hash_32_t { | ||||
|   return create_hash_blake2b_t<hash_32_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(wchar_t)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_32(const data_buffer &data) -> hash_32_t { | ||||
|   return create_hash_blake2b_t<hash_32_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(data_buffer::value_type)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_64(std::string_view data) -> hash_64_t { | ||||
|   return create_hash_blake2b_t<hash_64_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), data.size()); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_64(std::wstring_view data) -> hash_64_t { | ||||
|   return create_hash_blake2b_t<hash_64_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(wchar_t)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_64(const data_buffer &data) -> hash_64_t { | ||||
|   return create_hash_blake2b_t<hash_64_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(data_buffer::value_type)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_128(std::string_view data) -> hash_128_t { | ||||
|   return create_hash_blake2b_t<hash_128_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), data.size()); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_128(std::wstring_view data) -> hash_128_t { | ||||
|   return create_hash_blake2b_t<hash_128_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(wchar_t)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_128(const data_buffer &data) -> hash_128_t { | ||||
|   return create_hash_blake2b_t<hash_128_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), | ||||
|       data.size() * sizeof(data_buffer::value_type)); | ||||
| } | ||||
|  | ||||
| auto create_hash_blake2b_256(std::string_view data) -> hash_256_t { | ||||
|   return create_hash_blake2b_t<hash_256_t>( | ||||
|       reinterpret_cast<const unsigned char *>(data.data()), data.size()); | ||||
|   | ||||
| @@ -36,10 +36,49 @@ auto from_dynamic_bitset(const boost::dynamic_bitset<> &bitset) -> std::string { | ||||
| #endif // defined(PROJECT_ENABLE_BOOST) | ||||
|  | ||||
| auto from_utf8(std::string_view str) -> std::wstring { | ||||
|   return str.empty() | ||||
|              ? L"" | ||||
|              : std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>() | ||||
|                    .from_bytes(std::string{str}); | ||||
|   if (str.empty()) { | ||||
|     return L""; | ||||
|   } | ||||
|  | ||||
|   std::wstring out; | ||||
|  | ||||
|   const auto *str_ptr = reinterpret_cast<const std::uint8_t *>(str.data()); | ||||
|   std::int32_t idx{}; | ||||
|   auto len{static_cast<std::int32_t>(str.size())}; | ||||
|  | ||||
| #if WCHAR_MAX <= 0xFFFF | ||||
|   out.reserve((str.size() + 1U) / 2U); | ||||
|   while (idx < len) { | ||||
|     UChar32 uni_ch{}; | ||||
|     U8_NEXT(str_ptr, idx, len, uni_ch); | ||||
|     if (uni_ch < 0 || !U_IS_UNICODE_CHAR(uni_ch)) { | ||||
|       throw std::runtime_error("from_utf8: invalid UTF-8 sequence"); | ||||
|     } | ||||
|     std::array<UChar, 2U> units{}; | ||||
|     std::int32_t off{}; | ||||
|     auto err{false}; | ||||
|     U16_APPEND(units.data(), off, 2, uni_ch, err); | ||||
|     if (err || off <= 0) { | ||||
|       throw std::runtime_error("from_utf8: U16_APPEND failed"); | ||||
|     } | ||||
|     out.push_back(static_cast<wchar_t>(units[0U])); | ||||
|     if (off == 2) { | ||||
|       out.push_back(static_cast<wchar_t>(units[1U])); | ||||
|     } | ||||
|   } | ||||
| #else  // WCHAR_MAX > 0xFFFF | ||||
|   out.reserve(str.size()); | ||||
|   while (idx < len) { | ||||
|     UChar32 uni_ch{}; | ||||
|     U8_NEXT(str_ptr, idx, len, uni_ch); | ||||
|     if (uni_ch < 0 || !U_IS_UNICODE_CHAR(uni_ch)) { | ||||
|       throw std::runtime_error("from_utf8: invalid UTF-8 sequence"); | ||||
|     } | ||||
|     out.push_back(static_cast<wchar_t>(uni_ch)); | ||||
|   } | ||||
| #endif // WCHAR_MAX <= 0xFFFF | ||||
|  | ||||
|   return out; | ||||
| } | ||||
|  | ||||
| #if defined(PROJECT_ENABLE_SFML) | ||||
| @@ -55,8 +94,8 @@ auto replace_sf(sf::String &src, const sf::String &find, const sf::String &with, | ||||
|   return src; | ||||
| } | ||||
|  | ||||
| auto split_sf(sf::String str, wchar_t delim, | ||||
|               bool should_trim) -> std::vector<sf::String> { | ||||
| auto split_sf(sf::String str, wchar_t delim, bool should_trim) | ||||
|     -> std::vector<sf::String> { | ||||
|   auto result = std::views::split(str.toWideString(), delim); | ||||
|  | ||||
|   std::vector<sf::String> ret{}; | ||||
| @@ -130,9 +169,51 @@ auto to_uint64(const std::string &val) -> std::uint64_t { | ||||
| auto to_utf8(std::string_view str) -> std::string { return std::string{str}; } | ||||
|  | ||||
| auto to_utf8(std::wstring_view str) -> std::string { | ||||
|   return str.empty() | ||||
|              ? "" | ||||
|              : std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>() | ||||
|                    .to_bytes(std::wstring{str}); | ||||
|   if (str.empty()) { | ||||
|     return ""; | ||||
|   } | ||||
|  | ||||
|   std::string out; | ||||
|   out.reserve(static_cast<size_t>(str.size()) * 4); | ||||
|  | ||||
| #if WCHAR_MAX <= 0xFFFF | ||||
|   const auto *u16 = reinterpret_cast<const UChar *>(str.data()); | ||||
|   std::int32_t idx{}; | ||||
|   auto len{static_cast<int32_t>(str.size())}; | ||||
|   while (idx < len) { | ||||
|     UChar32 uni_ch{}; | ||||
|     U16_NEXT(u16, idx, len, uni_ch); | ||||
|     if (uni_ch < 0 || !U_IS_UNICODE_CHAR(uni_ch)) { | ||||
|       throw std::runtime_error("to_utf8: invalid UTF-16 sequence"); | ||||
|     } | ||||
|     std::array<std::uint8_t, U8_MAX_LENGTH> buf{}; | ||||
|     std::int32_t off{0}; | ||||
|     auto err{false}; | ||||
|     U8_APPEND(buf.data(), off, U8_MAX_LENGTH, uni_ch, err); | ||||
|     if (err || off <= 0) { | ||||
|       throw std::runtime_error("to_utf8: U8_APPEND failed"); | ||||
|     } | ||||
|     out.append(reinterpret_cast<const char *>(buf.data()), | ||||
|                static_cast<std::size_t>(off)); | ||||
|   } | ||||
| #else  // WCHAR_MAX > 0xFFFF | ||||
|   for (auto cur_ch : str) { | ||||
|     auto uni_char{static_cast<UChar32>(cur_ch)}; | ||||
|     if (!U_IS_UNICODE_CHAR(uni_char)) { | ||||
|       throw std::runtime_error("to_utf8: invalid Unicode scalar value"); | ||||
|     } | ||||
|     std::array<std::uint8_t, U8_MAX_LENGTH> buf{}; | ||||
|     std::int32_t off{0}; | ||||
|     auto err{false}; | ||||
|     U8_APPEND(buf.data(), off, U8_MAX_LENGTH, uni_char, err); | ||||
|     if (err || off <= 0) { | ||||
|       throw std::runtime_error("to_utf8: U8_APPEND failed"); | ||||
|     } | ||||
|     out.append(reinterpret_cast<const char *>(buf.data()), | ||||
|                static_cast<std::size_t>(off)); | ||||
|   } | ||||
| #endif // WCHAR_MAX <= 0xFFFF | ||||
|  | ||||
|   return out; | ||||
| } | ||||
| } // namespace repertory::utils::string | ||||
|   | ||||
| @@ -23,7 +23,6 @@ | ||||
|  | ||||
| #include "utils/windows.hpp" | ||||
|  | ||||
| #include "utils/com_init_wrapper.hpp" | ||||
| #include "utils/error.hpp" | ||||
| #include "utils/string.hpp" | ||||
|  | ||||
| @@ -65,7 +64,6 @@ auto get_local_app_data_directory() -> const std::string & { | ||||
|   REPERTORY_USES_FUNCTION_NAME(); | ||||
|  | ||||
|   static std::string app_data = ([]() -> std::string { | ||||
|     com_init_wrapper cw; | ||||
|     PWSTR local_app_data{}; | ||||
|     if (SUCCEEDED(::SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, | ||||
|                                          &local_app_data))) { | ||||
| @@ -139,6 +137,142 @@ auto run_process_elevated(std::vector<const char *> args) -> int { | ||||
| } | ||||
|  | ||||
| void set_last_error_code(DWORD error_code) { ::SetLastError(error_code); } | ||||
|  | ||||
| auto get_startup_folder() -> std::wstring { | ||||
|   PWSTR raw{nullptr}; | ||||
|   auto result = ::SHGetKnownFolderPath(FOLDERID_Startup, 0, nullptr, &raw); | ||||
|   if (FAILED(result)) { | ||||
|     if (raw != nullptr) { | ||||
|       ::CoTaskMemFree(raw); | ||||
|     } | ||||
|  | ||||
|     return {}; | ||||
|   } | ||||
|  | ||||
|   std::wstring str{raw}; | ||||
|   ::CoTaskMemFree(raw); | ||||
|   return str; | ||||
| } | ||||
|  | ||||
| auto create_shortcut(const std::wstring &exe_path, | ||||
|                      const std::wstring &arguments, | ||||
|                      const std::wstring &working_directory, | ||||
|                      const std::wstring &shortcut_name, std::wstring location) | ||||
|     -> bool { | ||||
|   REPERTORY_USES_FUNCTION_NAME(); | ||||
|  | ||||
|   const auto hr_hex = [](HRESULT hr) -> std::string { | ||||
|     std::ostringstream oss; | ||||
|     oss << "0x" << std::uppercase << std::hex << std::setw(8) | ||||
|         << std::setfill('0') << static_cast<std::uint32_t>(hr); | ||||
|     return oss.str(); | ||||
|   }; | ||||
|  | ||||
|   if (location.empty()) { | ||||
|     utils::error::handle_error(function_name, "Shortcut location was empty."); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   { | ||||
|     std::error_code ec_mk; | ||||
|     std::filesystem::create_directories(std::filesystem::path{location}, ec_mk); | ||||
|   } | ||||
|  | ||||
|   std::filesystem::path exe_p{exe_path}; | ||||
|   std::wstring final_name = shortcut_name.empty() | ||||
|                                 ? (exe_p.stem().wstring() + L".lnk") | ||||
|                                 : shortcut_name; | ||||
|   if (not final_name.ends_with(L".lnk")) { | ||||
|     final_name += L".lnk"; | ||||
|   } | ||||
|  | ||||
|   const std::filesystem::path lnk_path = | ||||
|       std::filesystem::path{location} / final_name; | ||||
|  | ||||
|   IShellLinkW *psl{nullptr}; | ||||
|   HRESULT result = ::CoCreateInstance(CLSID_ShellLink, nullptr, | ||||
|                                       CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl)); | ||||
|   if (FAILED(result)) { | ||||
|     utils::error::handle_error( | ||||
|         function_name, | ||||
|         std::string("CoCreateInstance(CLSID_ShellLink) failed: ") + | ||||
|             hr_hex(result)); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   result = psl->SetPath(exe_path.c_str()); | ||||
|   if (FAILED(result)) { | ||||
|     utils::error::handle_error(function_name, | ||||
|                                std::string("IShellLink::SetPath failed: ") + | ||||
|                                    hr_hex(result)); | ||||
|     psl->Release(); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   if (not arguments.empty()) { | ||||
|     result = psl->SetArguments(arguments.c_str()); | ||||
|     if (FAILED(result)) { | ||||
|       utils::error::handle_error( | ||||
|           function_name, | ||||
|           std::string("IShellLink::SetArguments failed: ") + hr_hex(result)); | ||||
|       psl->Release(); | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (not working_directory.empty()) { | ||||
|     result = psl->SetWorkingDirectory(working_directory.c_str()); | ||||
|     if (FAILED(result)) { | ||||
|       utils::error::handle_error( | ||||
|           function_name, | ||||
|           std::string("IShellLink::SetWorkingDirectory failed: ") + | ||||
|               hr_hex(result)); | ||||
|       psl->Release(); | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   result = psl->SetShowCmd(SW_SHOWNORMAL); | ||||
|   if (FAILED(result)) { | ||||
|     utils::error::handle_error(function_name, | ||||
|                                std::string("IShellLink::SetShowCmd failed: ") + | ||||
|                                    hr_hex(result)); | ||||
|     psl->Release(); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   // Best-effort overwrite | ||||
|   { | ||||
|     std::error_code ec; | ||||
|     std::filesystem::remove(lnk_path, ec); | ||||
|   } | ||||
|  | ||||
|   IPersistFile *ppf{nullptr}; | ||||
|   result = psl->QueryInterface(IID_PPV_ARGS(&ppf)); | ||||
|   if (FAILED(result)) { | ||||
|     utils::error::handle_error( | ||||
|         function_name, | ||||
|         std::string("QueryInterface(IPersistFile) failed: ") + hr_hex(result)); | ||||
|     psl->Release(); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   result = ppf->Save(lnk_path.c_str(), TRUE); | ||||
|   ppf->SaveCompleted(lnk_path.c_str()); | ||||
|  | ||||
|   ppf->Release(); | ||||
|   psl->Release(); | ||||
|  | ||||
|   if (FAILED(result)) { | ||||
|     utils::error::handle_error(function_name, | ||||
|                                std::string("IPersistFile::Save failed: ") + | ||||
|                                    hr_hex(result)); | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| } // namespace repertory::utils | ||||
|  | ||||
| #endif // defined(_WIN32) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user