| 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}; |
| 62 | if (should_encrypt_on_write_) { |
| 63 | // allow a possible exception to propagate upward |
| 64 | // if we fail to encrypt the file DON'T just write |
| 65 | // it as-is |
| 66 | logger_->log_debug("Encrypting file %s", file_name); |
| 67 | output << encryptor_->encrypt(file_content); |
| 68 | } else { |
| 69 | logger_->log_debug("No encryption is required for file %s", file_name); |
| 70 | output << file_content; |
| 71 | } |
| 72 | output.close(); |
| 73 | return static_cast<bool>(output); |
| 74 | } |
| 75 | |
| 76 | } // namespace file |
| 77 | } // namespace utils |