Fix warning from static analysis tool about std::moving a large CryConfig object

This commit is contained in:
Sebastian Messmer 2016-09-24 11:42:57 +02:00
parent 116a90be6d
commit 789bfc7527
4 changed files with 12 additions and 7 deletions

View File

@ -28,6 +28,10 @@ CryConfig::CryConfig(CryConfig &&rhs)
: _rootBlob(std::move(rhs._rootBlob)), _encKey(std::move(rhs._encKey)), _cipher(std::move(rhs._cipher)), _version(std::move(rhs._version)), _createdWithVersion(std::move(rhs._createdWithVersion)), _blocksizeBytes(rhs._blocksizeBytes), _filesystemId(std::move(rhs._filesystemId)) {
}
CryConfig::CryConfig(const CryConfig &rhs)
: _rootBlob(rhs._rootBlob), _encKey(rhs._encKey), _cipher(rhs._cipher), _version(rhs._version), _createdWithVersion(rhs._createdWithVersion), _blocksizeBytes(rhs._blocksizeBytes), _filesystemId(rhs._filesystemId) {
}
CryConfig CryConfig::load(const Data &data) {
stringstream stream;
data.StoreToStream(stream);

View File

@ -15,6 +15,7 @@ public:
//TODO No default constructor, pass in config values instead!
CryConfig();
CryConfig(CryConfig &&rhs);
CryConfig(const CryConfig &rhs);
const std::string &RootBlob() const;
void SetRootBlob(const std::string &value);
@ -50,7 +51,7 @@ private:
uint64_t _blocksizeBytes;
FilesystemID _filesystemId;
DISALLOW_COPY_AND_ASSIGN(CryConfig);
CryConfig &operator=(const CryConfig &rhs) = delete;
};
}

View File

@ -53,17 +53,17 @@ optional<CryConfigFile> CryConfigFile::load(const bf::path &path, const string &
return std::move(configFile);
}
CryConfigFile CryConfigFile::create(const bf::path &path, CryConfig config, const string &password, const SCryptSettings &scryptSettings) {
CryConfigFile CryConfigFile::create(const bf::path &path, const CryConfig &config, const string &password, const SCryptSettings &scryptSettings) {
if (bf::exists(path)) {
throw std::runtime_error("Config file exists already.");
}
auto result = CryConfigFile(path, std::move(config), CryConfigEncryptorFactory::deriveKey(password, scryptSettings));
auto result = CryConfigFile(path, config, CryConfigEncryptorFactory::deriveKey(password, scryptSettings));
result.save();
return result;
}
CryConfigFile::CryConfigFile(const bf::path &path, CryConfig config, unique_ref<CryConfigEncryptor> encryptor)
: _path (path), _config(std::move(config)), _encryptor(std::move(encryptor)) {
CryConfigFile::CryConfigFile(const bf::path &path, const CryConfig &config, unique_ref<CryConfigEncryptor> encryptor)
: _path (path), _config(config), _encryptor(std::move(encryptor)) {
}
void CryConfigFile::save() const {

View File

@ -14,14 +14,14 @@ namespace cryfs {
CryConfigFile(CryConfigFile &&rhs) = default;
~CryConfigFile();
static CryConfigFile create(const boost::filesystem::path &path, CryConfig config, const std::string &password, const cpputils::SCryptSettings &scryptSettings);
static CryConfigFile create(const boost::filesystem::path &path, const CryConfig &config, const std::string &password, const cpputils::SCryptSettings &scryptSettings);
static boost::optional<CryConfigFile> load(const boost::filesystem::path &path, const std::string &password);
void save() const;
CryConfig *config();
private:
CryConfigFile(const boost::filesystem::path &path, CryConfig config, cpputils::unique_ref<CryConfigEncryptor> encryptor);
CryConfigFile(const boost::filesystem::path &path, const CryConfig &config, cpputils::unique_ref<CryConfigEncryptor> encryptor);
boost::filesystem::path _path;
CryConfig _config;