1919#include " base/settings/json_settings.h"
2020
2121#include " base/logging.h"
22- #include " base/crypto/os_crypt.h"
2322#include " base/files/base_paths.h"
2423#include " base/files/file_util.h"
2524#include " base/files/scoped_temp_file.h"
@@ -95,8 +94,7 @@ void parseObject(const T& object, std::vector<std::string_view>* segments, Setti
9594} // namespace
9695
9796// --------------------------------------------------------------------------------------------------
98- JsonSettings::JsonSettings (std::string_view file_name, Encrypted encrypted)
99- : encrypted_(encrypted)
97+ JsonSettings::JsonSettings (std::string_view file_name)
10098{
10199 path_ = filePath (file_name);
102100 if (path_.empty ())
@@ -108,9 +106,7 @@ JsonSettings::JsonSettings(std::string_view file_name, Encrypted encrypted)
108106// --------------------------------------------------------------------------------------------------
109107JsonSettings::JsonSettings (Scope scope,
110108 std::string_view application_name,
111- std::string_view file_name,
112- Encrypted encrypted)
113- : encrypted_(encrypted)
109+ std::string_view file_name)
114110{
115111 path_ = filePath (scope, application_name, file_name);
116112 if (path_.empty ())
@@ -152,7 +148,7 @@ bool JsonSettings::isWritable() const
152148// --------------------------------------------------------------------------------------------------
153149void JsonSettings::sync ()
154150{
155- readFile (path_, map (), encrypted_ );
151+ readFile (path_, map ());
156152 setChanged (false );
157153}
158154
@@ -167,7 +163,7 @@ bool JsonSettings::flush()
167163 }
168164
169165 // Write to the configuration file.
170- if (writeFile (path_, map (), encrypted_ ))
166+ if (writeFile (path_, map ()))
171167 {
172168 LOG (LS_INFO) << " Configuration file '" << path_ << " ' successfully written to disk" ;
173169 setChanged (false );
@@ -236,7 +232,7 @@ std::filesystem::path JsonSettings::filePath(Scope scope,
236232
237233// --------------------------------------------------------------------------------------------------
238234// static
239- bool JsonSettings::readFile (const std::filesystem::path& file, Map& map, Encrypted encrypted )
235+ bool JsonSettings::readFile (const std::filesystem::path& file, Map& map)
240236{
241237 map.clear ();
242238
@@ -246,7 +242,7 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
246242 if (!std::filesystem::exists (status))
247243 {
248244 // If the configuration file does not yet exist, then we write an empty file.
249- writeFile (file, map, encrypted );
245+ writeFile (file, map);
250246
251247 // The absence of a configuration file is normal case.
252248 return true ;
@@ -280,18 +276,6 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
280276 return false ;
281277 }
282278
283- if (encrypted == Encrypted::YES)
284- {
285- std::string decrypted;
286- if (!OSCrypt::decryptString (buffer, &decrypted))
287- {
288- LOG (LS_ERROR) << " Failed to decrypt config file: '" << file << " '" ;
289- return false ;
290- }
291-
292- buffer.swap (decrypted);
293- }
294-
295279 rapidjson::StringStream stream (buffer.data ());
296280 rapidjson::Document doc;
297281 doc.ParseStream (stream);
@@ -311,7 +295,7 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
311295
312296// --------------------------------------------------------------------------------------------------
313297// static
314- bool JsonSettings::writeFile (const std::filesystem::path& file, const Map& map, Encrypted encrypted )
298+ bool JsonSettings::writeFile (const std::filesystem::path& file, const Map& map)
315299{
316300 std::error_code error_code;
317301 if (!std::filesystem::create_directories (file.parent_path (), error_code))
@@ -379,31 +363,10 @@ bool JsonSettings::writeFile(const std::filesystem::path& file, const Map& map,
379363
380364 std::string_view source_buffer (buffer.GetString (), buffer.GetSize ());
381365
382- if (encrypted == Encrypted::YES )
366+ if (! base::writeFile (file, source_buffer) )
383367 {
384- std::string cipher_buffer;
385-
386- if (!OSCrypt::encryptString (source_buffer, &cipher_buffer))
387- {
388- LOG (LS_ERROR) << " Failed to encrypt config file" ;
389- return false ;
390- }
391-
392- if (!base::writeFile (file, cipher_buffer))
393- {
394- LOG (LS_ERROR) << " Failed to write config file" ;
395- return false ;
396- }
397- }
398- else
399- {
400- DCHECK_EQ (encrypted, Encrypted::NO);
401-
402- if (!base::writeFile (file, source_buffer))
403- {
404- LOG (LS_ERROR) << " Failed to write config file" ;
405- return false ;
406- }
368+ LOG (LS_ERROR) << " Failed to write config file" ;
369+ return false ;
407370 }
408371
409372 return true ;
0 commit comments