Better logging when local state can't be loaded

This commit is contained in:
Sebastian Messmer 2019-05-25 12:27:31 -07:00
parent 0ee707397d
commit 7d40937b9a
4 changed files with 33 additions and 15 deletions

View File

@ -1,5 +1,7 @@
Version 0.10.2 (unreleased)
---------------
Improvements:
* Better logging when local state can't be loaded
Version 0.10.1

View File

@ -40,6 +40,7 @@ CryConfig::CryConfig()
CryConfig CryConfig::load(const Data &data) {
stringstream stream;
data.StoreToStream(stream);
ptree pt;
read_json(stream, pt);

View File

@ -4,6 +4,7 @@
#include <vendor_cryptopp/sha.h>
#include <boost/filesystem/operations.hpp>
#include "LocalStateDir.h"
#include <cpp-utils/logging/logging.h>
namespace bf = boost::filesystem;
using boost::property_tree::ptree;
@ -15,20 +16,27 @@ using std::istream;
using std::ifstream;
using std::ofstream;
using std::string;
using namespace cpputils::logging;
namespace cryfs {
namespace {
ptree _load(const bf::path &metadataFilePath) {
ptree result;
try {
ptree result;
ifstream file(metadataFilePath.string());
if (file.good()) {
read_json(file, result);
}
ifstream file(metadataFilePath.string());
if (file.good()) {
read_json(file, result);
}
return result;
return result;
}
catch (...) {
LOG(ERR, "Error loading BasedirMetadata");
throw;
}
}
void _save(const bf::path &metadataFilePath, const ptree& data) {

View File

@ -21,6 +21,7 @@ using cpputils::hash::Hash;
using cpputils::Data;
using cpputils::Random;
namespace bf = boost::filesystem;
using namespace cpputils::logging;
namespace cryfs {
@ -106,17 +107,23 @@ void LocalStateMetadata::_serialize(ostream& stream) const {
}
LocalStateMetadata LocalStateMetadata::_deserialize(istream& stream) {
ptree pt;
read_json(stream, pt);
try {
ptree pt;
read_json(stream, pt);
uint32_t myClientId = pt.get<uint32_t>("myClientId");
string encryptionKeySalt = pt.get<string>("encryptionKey.salt");
string encryptionKeyDigest = pt.get<string>("encryptionKey.hash");
uint32_t myClientId = pt.get<uint32_t>("myClientId");
string encryptionKeySalt = pt.get<string>("encryptionKey.salt");
string encryptionKeyDigest = pt.get<string>("encryptionKey.hash");
return LocalStateMetadata(myClientId, Hash{
/*.digest = */ cpputils::hash::Digest::FromString(encryptionKeyDigest),
/*.salt = */ cpputils::hash::Salt::FromString(encryptionKeySalt)
});
return LocalStateMetadata(myClientId, Hash{
/*.digest = */ cpputils::hash::Digest::FromString(encryptionKeyDigest),
/*.salt = */ cpputils::hash::Salt::FromString(encryptionKeySalt)
});
}
catch (...) {
LOG(ERR, "Error loading LocalStateMetadata");
throw;
}
}
}