| 39 | } |
| 40 | |
| 41 | utils::optional<std::string> FileSystem::read(const std::string& file_name) { |
| 42 | std::ifstream input{file_name, std::ios::binary}; |
| 43 | if (!input) { |
| 44 | return {}; |
| 45 | } |
| 46 | input.exceptions(std::ios::failbit | std::ios::badbit); |
| 47 | std::string content{std::istreambuf_iterator<char>(input), {}}; |
| 48 | if (encryptor_) { |
| 49 | try { |
| 50 | logger_->log_debug("Trying to decrypt file %s", file_name); |
| 51 | content = encryptor_->decrypt(content); |
| 52 | } catch(...) { |
| 53 | // tried to decrypt file but failed, use file as-is |
| 54 | logger_->log_debug("Decrypting file %s failed, using the file as-is", file_name); |
| 55 | } |
| 56 | } |
| 57 | return content; |
| 58 | } |
| 59 | |
| 60 | bool FileSystem::write(const std::string& file_name, const std::string& file_content) { |
| 61 | std::ofstream output{file_name, std::ios::binary}; |
no test coverage detected