From 3d9d2323c854f7b72dd067698745dbf7ef8a8b33 Mon Sep 17 00:00:00 2001 From: AmnaSnene Date: Wed, 14 Aug 2024 10:28:45 -0400 Subject: [PATCH] Raise an error if any Identity file fails to save --- src/crypto.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/crypto.cpp b/src/crypto.cpp index ac970bbee..1d578b5fc 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -1164,11 +1164,17 @@ saveIdentity(const Identity& id, const std::string& path, const std::string& pri auto ca_key_data = id.first->serialize(privkey_password); std::ofstream key_file(path + ".pem"); key_file.write((char*)ca_key_data.data(), ca_key_data.size()); + // Throw error if the file is not written + if (!key_file) + throw CryptoException("Could not write private key file"); } { auto ca_key_data = id.second->getPacked(); std::ofstream crt_file(path + ".crt"); crt_file.write((char*)ca_key_data.data(), ca_key_data.size()); + // Throw error if the file is not written + if (!crt_file) + throw CryptoException("Could not write certificate file"); } }