diff --git a/rmw_dds_common/CMakeLists.txt b/rmw_dds_common/CMakeLists.txt index a85bbeb..38a3a89 100644 --- a/rmw_dds_common/CMakeLists.txt +++ b/rmw_dds_common/CMakeLists.txt @@ -21,7 +21,6 @@ find_package(rosidl_runtime_c REQUIRED) ament_add_default_options() ament_export_dependencies(ament_cmake_core) -ament_export_dependencies(rcpputils) ament_export_dependencies(rcutils) ament_export_dependencies(rmw) diff --git a/rmw_dds_common/src/security.cpp b/rmw_dds_common/src/security.cpp index d385449..701ebba 100644 --- a/rmw_dds_common/src/security.cpp +++ b/rmw_dds_common/src/security.cpp @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include -#include "rcpputils/filesystem_helper.hpp" #include "rmw_dds_common/security.hpp" namespace rmw_dds_common @@ -40,21 +40,21 @@ bool get_security_files( }; for (const std::pair & el : required_files) { - rcpputils::fs::path full_path(secure_root); + std::filesystem::path full_path(secure_root); full_path /= el.second; - if (!full_path.is_regular_file()) { + if (!std::filesystem::is_regular_file(full_path)) { result.clear(); return false; } - result[el.first] = prefix + full_path.string(); + result[el.first] = prefix + full_path.generic_string(); } for (const std::pair & el : optional_files) { - rcpputils::fs::path full_path(secure_root); + std::filesystem::path full_path(secure_root); full_path /= el.second; - if (full_path.is_regular_file()) { - result[el.first] = prefix + full_path.string(); + if (std::filesystem::is_regular_file(full_path)) { + result[el.first] = prefix + full_path.generic_string(); } } diff --git a/rmw_dds_common/test/test_security.cpp b/rmw_dds_common/test/test_security.cpp index 53b5496..e1fa36c 100644 --- a/rmw_dds_common/test/test_security.cpp +++ b/rmw_dds_common/test/test_security.cpp @@ -13,165 +13,165 @@ // limitations under the License. #include +#include #include #include #include #include "gtest/gtest.h" -#include "rcpputils/filesystem_helper.hpp" #include "rmw_dds_common/security.hpp" TEST(test_security, files_exist_no_prefix) { - rcpputils::fs::path dir = rcpputils::fs::path("./test_folder"); - rcpputils::fs::remove_all(dir); - EXPECT_TRUE(rcpputils::fs::create_directories(dir)); - EXPECT_TRUE(rcpputils::fs::exists(dir)); - EXPECT_TRUE(rcpputils::fs::is_directory(dir)); + std::filesystem::path dir = std::filesystem::path("./test_folder"); + std::filesystem::remove_all(dir); + EXPECT_TRUE(std::filesystem::create_directories(dir)); + EXPECT_TRUE(std::filesystem::exists(dir)); + EXPECT_TRUE(std::filesystem::is_directory(dir)); std::array required_files = { "identity_ca.cert.pem", "cert.pem", "key.pem", "permissions_ca.cert.pem", "governance.p7s", "permissions.p7s" }; for (const std::string & filename : required_files) { - rcpputils::fs::path full_path = dir / filename; - std::ofstream output_buffer{full_path.string()}; + std::filesystem::path full_path = dir / filename; + std::ofstream output_buffer{full_path.generic_string()}; output_buffer << "test"; - ASSERT_TRUE(rcpputils::fs::exists(full_path)); + ASSERT_TRUE(std::filesystem::exists(full_path)); } std::unordered_map security_files; - ASSERT_TRUE(rmw_dds_common::get_security_files("", dir.string(), security_files)); + ASSERT_TRUE(rmw_dds_common::get_security_files("", dir.generic_string(), security_files)); EXPECT_EQ( security_files["IDENTITY_CA"], - rcpputils::fs::path("./test_folder/identity_ca.cert.pem").string()); + std::filesystem::path("./test_folder/identity_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["CERTIFICATE"], - rcpputils::fs::path("./test_folder/cert.pem").string()); + std::filesystem::path("./test_folder/cert.pem").generic_string()); EXPECT_EQ( security_files["PRIVATE_KEY"], - rcpputils::fs::path("./test_folder/key.pem").string()); + std::filesystem::path("./test_folder/key.pem").generic_string()); EXPECT_EQ( security_files["PERMISSIONS_CA"], - rcpputils::fs::path("./test_folder/permissions_ca.cert.pem").string()); + std::filesystem::path("./test_folder/permissions_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["GOVERNANCE"], - rcpputils::fs::path("./test_folder/governance.p7s").string()); + std::filesystem::path("./test_folder/governance.p7s").generic_string()); EXPECT_EQ( security_files["PERMISSIONS"], - rcpputils::fs::path("./test_folder/permissions.p7s").string()); + std::filesystem::path("./test_folder/permissions.p7s").generic_string()); } TEST(test_security, files_exist_with_prefix) { - rcpputils::fs::path dir = rcpputils::fs::path("./test_folder"); - rcpputils::fs::remove_all(dir); - EXPECT_TRUE(rcpputils::fs::create_directories(dir)); - EXPECT_TRUE(rcpputils::fs::exists(dir)); - EXPECT_TRUE(rcpputils::fs::is_directory(dir)); + std::filesystem::path dir = std::filesystem::path("./test_folder"); + std::filesystem::remove_all(dir); + EXPECT_TRUE(std::filesystem::create_directories(dir)); + EXPECT_TRUE(std::filesystem::exists(dir)); + EXPECT_TRUE(std::filesystem::is_directory(dir)); std::array required_files = { "identity_ca.cert.pem", "cert.pem", "key.pem", "permissions_ca.cert.pem", "governance.p7s", "permissions.p7s" }; for (const std::string & filename : required_files) { - rcpputils::fs::path full_path = dir / filename; - std::ofstream output_buffer{full_path.string()}; + std::filesystem::path full_path = dir / filename; + std::ofstream output_buffer{full_path.generic_string()}; output_buffer << "test"; - ASSERT_TRUE(rcpputils::fs::exists(full_path)); + ASSERT_TRUE(std::filesystem::exists(full_path)); } std::unordered_map security_files; - ASSERT_TRUE(rmw_dds_common::get_security_files("file://", dir.string(), security_files)); + ASSERT_TRUE(rmw_dds_common::get_security_files("file://", dir.generic_string(), security_files)); EXPECT_EQ( security_files["IDENTITY_CA"], - "file://" + rcpputils::fs::path("./test_folder/identity_ca.cert.pem").string()); + "file://" + std::filesystem::path("./test_folder/identity_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["CERTIFICATE"], - "file://" + rcpputils::fs::path("./test_folder/cert.pem").string()); + "file://" + std::filesystem::path("./test_folder/cert.pem").generic_string()); EXPECT_EQ( security_files["PRIVATE_KEY"], - "file://" + rcpputils::fs::path("./test_folder/key.pem").string()); + "file://" + std::filesystem::path("./test_folder/key.pem").generic_string()); EXPECT_EQ( security_files["PERMISSIONS_CA"], - "file://" + rcpputils::fs::path("./test_folder/permissions_ca.cert.pem").string()); + "file://" + std::filesystem::path("./test_folder/permissions_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["GOVERNANCE"], - "file://" + rcpputils::fs::path("./test_folder/governance.p7s").string()); + "file://" + std::filesystem::path("./test_folder/governance.p7s").generic_string()); EXPECT_EQ( security_files["PERMISSIONS"], - "file://" + rcpputils::fs::path("./test_folder/permissions.p7s").string()); + "file://" + std::filesystem::path("./test_folder/permissions.p7s").generic_string()); } TEST(test_security, file_missing) { - rcpputils::fs::path dir = rcpputils::fs::path("./test_folder"); - rcpputils::fs::remove_all(dir); - EXPECT_TRUE(rcpputils::fs::create_directories(dir)); - EXPECT_TRUE(rcpputils::fs::exists(dir)); - EXPECT_TRUE(rcpputils::fs::is_directory(dir)); + std::filesystem::path dir = std::filesystem::path("./test_folder"); + std::filesystem::remove_all(dir); + EXPECT_TRUE(std::filesystem::create_directories(dir)); + EXPECT_TRUE(std::filesystem::exists(dir)); + EXPECT_TRUE(std::filesystem::is_directory(dir)); std::array required_files = { "identity_ca.cert.pem", "cert.pem", "key.pem", "permissions_ca.cert.pem", "governance.p7s" }; for (const std::string & filename : required_files) { - rcpputils::fs::path full_path = dir / filename; - std::ofstream output_buffer{full_path.string()}; + std::filesystem::path full_path = dir / filename; + std::ofstream output_buffer{full_path.generic_string()}; output_buffer << "test"; - ASSERT_TRUE(rcpputils::fs::exists(full_path)); + ASSERT_TRUE(std::filesystem::exists(full_path)); } std::unordered_map security_files; - ASSERT_FALSE(rmw_dds_common::get_security_files("", dir.string(), security_files)); + ASSERT_FALSE(rmw_dds_common::get_security_files("", dir.generic_string(), security_files)); ASSERT_EQ(security_files.size(), 0UL); } TEST(test_security, optional_file_exist) { - rcpputils::fs::path dir = rcpputils::fs::path("./test_folder"); - rcpputils::fs::remove_all(dir); - EXPECT_TRUE(rcpputils::fs::create_directories(dir)); - EXPECT_TRUE(rcpputils::fs::exists(dir)); - EXPECT_TRUE(rcpputils::fs::is_directory(dir)); + std::filesystem::path dir = std::filesystem::path("./test_folder"); + std::filesystem::remove_all(dir); + EXPECT_TRUE(std::filesystem::create_directories(dir)); + EXPECT_TRUE(std::filesystem::exists(dir)); + EXPECT_TRUE(std::filesystem::is_directory(dir)); std::array required_files = { "identity_ca.cert.pem", "cert.pem", "key.pem", "permissions_ca.cert.pem", "governance.p7s", "permissions.p7s", "crl.pem", }; for (const std::string & filename : required_files) { - rcpputils::fs::path full_path = dir / filename; - std::ofstream output_buffer{full_path.string()}; + std::filesystem::path full_path = dir / filename; + std::ofstream output_buffer{full_path.generic_string()}; output_buffer << "test"; - ASSERT_TRUE(rcpputils::fs::exists(full_path)); + ASSERT_TRUE(std::filesystem::exists(full_path)); } std::unordered_map security_files; - ASSERT_TRUE(rmw_dds_common::get_security_files("", dir.string(), security_files)); + ASSERT_TRUE(rmw_dds_common::get_security_files("", dir.generic_string(), security_files)); EXPECT_EQ( security_files["IDENTITY_CA"], - rcpputils::fs::path("./test_folder/identity_ca.cert.pem").string()); + std::filesystem::path("./test_folder/identity_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["CERTIFICATE"], - rcpputils::fs::path("./test_folder/cert.pem").string()); + std::filesystem::path("./test_folder/cert.pem").generic_string()); EXPECT_EQ( security_files["PRIVATE_KEY"], - rcpputils::fs::path("./test_folder/key.pem").string()); + std::filesystem::path("./test_folder/key.pem").generic_string()); EXPECT_EQ( security_files["PERMISSIONS_CA"], - rcpputils::fs::path("./test_folder/permissions_ca.cert.pem").string()); + std::filesystem::path("./test_folder/permissions_ca.cert.pem").generic_string()); EXPECT_EQ( security_files["GOVERNANCE"], - rcpputils::fs::path("./test_folder/governance.p7s").string()); + std::filesystem::path("./test_folder/governance.p7s").generic_string()); EXPECT_EQ( security_files["PERMISSIONS"], - rcpputils::fs::path("./test_folder/permissions.p7s").string()); + std::filesystem::path("./test_folder/permissions.p7s").generic_string()); EXPECT_EQ( security_files["CRL"], - rcpputils::fs::path("./test_folder/crl.pem").string()); + std::filesystem::path("./test_folder/crl.pem").generic_string()); }