Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / certificate_validation.cc
index f5dd03f..4975f96 100644 (file)
@@ -4,13 +4,11 @@
 
 #include "common/certificate_validation.h"
 
-#include <boost/format.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/scope_exit.hpp>
 #include <vcore/Certificate.h>
 #include <vcore/SignatureValidator.h>
 
 #include <algorithm>
+#include <filesystem>
 #include <fstream>
 #include <regex>
 #include <utility>
@@ -20,8 +18,8 @@
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
-namespace bf = boost::filesystem;
 namespace ci = common_installer;
+namespace fs = std::filesystem;
 
 namespace {
 
@@ -165,7 +163,7 @@ void SetPrivilegeLevel(const ValidationCore::SignatureData& data,
 }
 
 bool ValidateSignatureFile(
-    const bf::path& base_path,
+    const fs::path& base_path,
     const ValidationCore::SignatureFileInfo& file_info,
     common_installer::PrivilegeLevel* level,
     common_installer::CertificateInfo* cert_info,
@@ -227,11 +225,11 @@ bool CheckAuthorSignature(const ValidationCore::SignatureFileInfo& file_info) {
 
 bool CheckDistSignature(const ValidationCore::SignatureFileInfo& file_info) {
   std::regex distributor_regex(kRegexDistributorSignature);
-  bf::path file_path(file_info.getFileName());
+  fs::path file_path(file_info.getFileName());
   return std::regex_search(file_path.filename().string(), distributor_regex);
 }
 
-bool ValidateSignatures(const bf::path& base_path,
+bool ValidateSignatures(const fs::path& base_path,
     PrivilegeLevel* level, common_installer::CertificateInfo* cert_info,
     bool check_reference, std::string* error_message) {
   // Find signature files
@@ -276,7 +274,7 @@ bool GetSignatureFromFile(const std::string& pkgid,
   CertSvcVisibility visibility = CERTSVC_VISIBILITY_DEVELOPER;
   std::string root_cert;
 
-  bf::path file_path((is_readonly_package) ?
+  fs::path file_path((is_readonly_package) ?
       tzplatform_getenv(TZ_SYS_RO_SHARE) : tzplatform_getenv(TZ_SYS_SHARE));
   file_path /= std::string("signatures/" + pkgid + ".txt");
   std::ifstream ifs(file_path.c_str(), std::ifstream::in);
@@ -332,6 +330,10 @@ bool GetSignatureFromFile(const std::string& pkgid,
   return true;
 }
 
+void FreePrivilegeList(GList* priv) {
+  g_list_free_full(priv, free);
+}
+
 bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level,
     uid_t uid, const char* api_version, GList* privileges,
     std::string* error_message) {
@@ -346,14 +348,12 @@ bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level,
 
   GList* native_privileges =
       ci::PrivilegeXToPrivilege(privileges, ci::kNativePrivilegeType);
-  BOOST_SCOPE_EXIT_ALL(&) {
-    g_list_free_full(native_privileges, free);
-  };
+  std::unique_ptr<GList, decltype(FreePrivilegeList)*> native_privs_deleter(
+      native_privileges, FreePrivilegeList);
   GList* web_privileges =
       ci::PrivilegeXToPrivilege(privileges, ci::kWebPrivilegeType);
-  BOOST_SCOPE_EXIT_ALL(&) {
-    g_list_free_full(web_privileges, free);
-  };
+  std::unique_ptr<GList, decltype(FreePrivilegeList)*> web_privs_deleter(
+      web_privileges, FreePrivilegeList);
 
   for (const std::pair<GList*, bool>& pair :
        std::initializer_list<std::pair<GList*, bool>>{