Optimize std::move use
This commit is contained in:
parent
0a7fce6701
commit
3787777967
@ -111,7 +111,7 @@ size_t CompressedBlock<Compressor>::size() const {
|
||||
|
||||
template<class Compressor>
|
||||
void CompressedBlock<Compressor>::resize(size_t newSize) {
|
||||
_decompressedData = cpputils::DataUtils::resize(std::move(_decompressedData), newSize);
|
||||
_decompressedData = cpputils::DataUtils::resize(_decompressedData, newSize);
|
||||
_dataChanged = true;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ size_t LowToHighLevelBlock::size() const {
|
||||
}
|
||||
|
||||
void LowToHighLevelBlock::resize(size_t newSize) {
|
||||
_data = DataUtils::resize(std::move(_data), newSize);
|
||||
_data = DataUtils::resize(_data, newSize);
|
||||
_dataChanged = true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ size_t FakeBlock::size() const {
|
||||
}
|
||||
|
||||
void FakeBlock::resize(size_t newSize) {
|
||||
*_data = cpputils::DataUtils::resize(std::move(*_data), newSize);
|
||||
*_data = cpputils::DataUtils::resize(*_data, newSize);
|
||||
_dataChanged = true;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace cpputils {
|
||||
|
||||
class AssertFailed final: public std::exception {
|
||||
public:
|
||||
AssertFailed(const std::string &message) : _message(message) { }
|
||||
AssertFailed(std::string message) : _message(std::move(message)) { }
|
||||
|
||||
const char *what() const throw() override {
|
||||
return _message.c_str();
|
||||
|
@ -27,7 +27,7 @@ private:
|
||||
constexpr static size_t BINARY_LENGTH = FixedSizeData<KeySize>::BINARY_LENGTH;
|
||||
constexpr static size_t STRING_LENGTH = FixedSizeData<KeySize>::STRING_LENGTH;
|
||||
|
||||
EncryptionKeyData(const FixedSizeData<KeySize >& keyData);
|
||||
EncryptionKeyData(const FixedSizeData<KeySize>& keyData);
|
||||
~EncryptionKeyData();
|
||||
|
||||
// Disallow copying and moving
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace cpputils {
|
||||
namespace DataUtils {
|
||||
Data resize(Data data, size_t newSize) {
|
||||
Data resize(const Data& data, size_t newSize) {
|
||||
Data newData(newSize);
|
||||
newData.FillWithZeroes(); // TODO Only fill region after copied old data with zeroes
|
||||
std::memcpy(newData.data(), data.data(), std::min(newData.size(), data.size()));
|
||||
|
@ -10,7 +10,7 @@ namespace cpputils {
|
||||
|
||||
//Return a new data object with the given size and initialize as much as possible with the given input data.
|
||||
//If the new data object is larger, then the remaining bytes will be zero filled.
|
||||
Data resize(Data data, size_t newSize);
|
||||
Data resize(const Data& data, size_t newSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace cpputils {
|
||||
|
||||
void get(void *target, size_t bytes);
|
||||
|
||||
void add(Data data);
|
||||
void add(const Data& data);
|
||||
|
||||
private:
|
||||
size_t _usedUntil;
|
||||
@ -37,7 +37,7 @@ namespace cpputils {
|
||||
_usedUntil += numBytes;
|
||||
}
|
||||
|
||||
inline void RandomDataBuffer::add(Data newData) {
|
||||
inline void RandomDataBuffer::add(const Data& newData) {
|
||||
// Concatenate old and new random data
|
||||
size_t oldSize = size();
|
||||
Data combined(oldSize + newData.size());
|
||||
|
@ -21,7 +21,7 @@ namespace cpputils {
|
||||
size_t neededRandomDataSize = _maxSize - _buffer->size();
|
||||
ASSERT(_maxSize > _buffer->size(), "This could theoretically fail if another thread refilled the buffer. But we should be the only refilling thread.");
|
||||
Data randomData = _generateRandomData(neededRandomDataSize);
|
||||
_buffer->add(std::move(randomData));
|
||||
_buffer->add(randomData);
|
||||
return true; // Run another iteration (don't terminate thread)
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace cpputils {
|
||||
|
||||
void get(void *target, size_t numBytes);
|
||||
|
||||
void add(Data data);
|
||||
void add(const Data& data);
|
||||
|
||||
void waitUntilSizeIsLessThan(size_t numBytes);
|
||||
|
||||
@ -63,9 +63,9 @@ namespace cpputils {
|
||||
return gettableBytes;
|
||||
}
|
||||
|
||||
inline void ThreadsafeRandomDataBuffer::add(Data data) {
|
||||
inline void ThreadsafeRandomDataBuffer::add(const Data& data) {
|
||||
boost::unique_lock<boost::mutex> lock(_mutex);
|
||||
_buffer.add(std::move(data));
|
||||
_buffer.add(data);
|
||||
_dataAddedCv.notify_all();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ using boost::none;
|
||||
|
||||
namespace cpputils {
|
||||
|
||||
LoopThread::LoopThread(function<bool()> loopIteration): _loopIteration(loopIteration), _runningHandle(none) {
|
||||
LoopThread::LoopThread(function<bool()> loopIteration): _loopIteration(std::move(loopIteration)), _runningHandle(none) {
|
||||
}
|
||||
|
||||
LoopThread::~LoopThread() {
|
||||
|
@ -19,7 +19,7 @@ namespace cpputils {
|
||||
|
||||
ThreadSystem::Handle ThreadSystem::start(function<bool()> loopIteration) {
|
||||
boost::unique_lock<boost::mutex> lock(_mutex);
|
||||
auto thread = _startThread(loopIteration);
|
||||
auto thread = _startThread(std::move(loopIteration));
|
||||
_runningThreads.push_back(RunningThread{loopIteration, std::move(thread)});
|
||||
return std::prev(_runningThreads.end());
|
||||
}
|
||||
@ -61,7 +61,9 @@ namespace cpputils {
|
||||
}
|
||||
|
||||
boost::thread ThreadSystem::_startThread(function<bool()> loopIteration) {
|
||||
return boost::thread(std::bind(&ThreadSystem::_runThread, loopIteration));
|
||||
return boost::thread([loopIteration = std::move(loopIteration)] {
|
||||
ThreadSystem::_runThread(std::move(loopIteration));
|
||||
});
|
||||
}
|
||||
|
||||
void ThreadSystem::_runThread(function<bool()> loopIteration) {
|
||||
|
@ -26,7 +26,7 @@ namespace cryfs {
|
||||
};
|
||||
|
||||
inline CallAfterTimeout::CallAfterTimeout(boost::chrono::milliseconds timeout, std::function<void()> callback)
|
||||
:_callback(callback), _timeout(timeout), _start(), _checkTimeoutThread(std::bind(&CallAfterTimeout::_checkTimeoutThreadIteration, this)) {
|
||||
:_callback(std::move(callback)), _timeout(timeout), _start(), _checkTimeoutThread(std::bind(&CallAfterTimeout::_checkTimeoutThreadIteration, this)) {
|
||||
resetTimer();
|
||||
_checkTimeoutThread.start();
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ namespace cryfs {
|
||||
CryConfigLoader::ConfigLoadResult Cli::_loadOrCreateConfig(const ProgramOptions &options) {
|
||||
try {
|
||||
auto configFile = _determineConfigFile(options);
|
||||
auto config = _loadOrCreateConfigFile(configFile, options.cipher(), options.blocksizeBytes(), options.missingBlockIsIntegrityViolation());
|
||||
auto config = _loadOrCreateConfigFile(std::move(configFile), options.cipher(), options.blocksizeBytes(), options.missingBlockIsIntegrityViolation());
|
||||
if (config == none) {
|
||||
std::cerr << "Could not load config file. Did you enter the correct password?" << std::endl;
|
||||
exit(1);
|
||||
@ -226,17 +226,17 @@ namespace cryfs {
|
||||
}
|
||||
}
|
||||
|
||||
optional<CryConfigLoader::ConfigLoadResult> Cli::_loadOrCreateConfigFile(const bf::path &configFilePath, const optional<string> &cipher, const optional<uint32_t> &blocksizeBytes, const optional<bool> &missingBlockIsIntegrityViolation) {
|
||||
optional<CryConfigLoader::ConfigLoadResult> Cli::_loadOrCreateConfigFile(bf::path configFilePath, const optional<string> &cipher, const optional<uint32_t> &blocksizeBytes, const optional<bool> &missingBlockIsIntegrityViolation) {
|
||||
if (_noninteractive) {
|
||||
return CryConfigLoader(_console, _keyGenerator, _scryptSettings,
|
||||
&Cli::_askPasswordNoninteractive,
|
||||
&Cli::_askPasswordNoninteractive,
|
||||
cipher, blocksizeBytes, missingBlockIsIntegrityViolation).loadOrCreate(configFilePath);
|
||||
cipher, blocksizeBytes, missingBlockIsIntegrityViolation).loadOrCreate(std::move(configFilePath));
|
||||
} else {
|
||||
return CryConfigLoader(_console, _keyGenerator, _scryptSettings,
|
||||
&Cli::_askPasswordForExistingFilesystem,
|
||||
&Cli::_askPasswordForNewFilesystem,
|
||||
cipher, blocksizeBytes, missingBlockIsIntegrityViolation).loadOrCreate(configFilePath);
|
||||
cipher, blocksizeBytes, missingBlockIsIntegrityViolation).loadOrCreate(std::move(configFilePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace cryfs {
|
||||
void _runFilesystem(const program_options::ProgramOptions &options);
|
||||
CryConfigLoader::ConfigLoadResult _loadOrCreateConfig(const program_options::ProgramOptions &options);
|
||||
void _checkConfigIntegrity(const boost::filesystem::path& basedir, const CryConfigFile& config);
|
||||
boost::optional<CryConfigLoader::ConfigLoadResult> _loadOrCreateConfigFile(const boost::filesystem::path &configFilePath, const boost::optional<std::string> &cipher, const boost::optional<uint32_t> &blocksizeBytes, const boost::optional<bool> &missingBlockIsIntegrityViolation);
|
||||
boost::optional<CryConfigLoader::ConfigLoadResult> _loadOrCreateConfigFile(boost::filesystem::path configFilePath, const boost::optional<std::string> &cipher, const boost::optional<uint32_t> &blocksizeBytes, const boost::optional<bool> &missingBlockIsIntegrityViolation);
|
||||
boost::filesystem::path _determineConfigFile(const program_options::ProgramOptions &options);
|
||||
static std::string _askPasswordForExistingFilesystem();
|
||||
static std::string _askPasswordForNewFilesystem();
|
||||
|
@ -92,7 +92,7 @@ ProgramOptions Parser::parse(const vector<string> &supportedCiphers) const {
|
||||
}
|
||||
}
|
||||
|
||||
return ProgramOptions(baseDir, mountDir, configfile, foreground, unmountAfterIdleMinutes, logfile, cipher, blocksizeBytes, noIntegrityChecks, missingBlockIsIntegrityViolation, fuseOptions);
|
||||
return ProgramOptions(std::move(baseDir), std::move(mountDir), std::move(configfile), foreground, std::move(unmountAfterIdleMinutes), std::move(logfile), std::move(cipher), blocksizeBytes, noIntegrityChecks, std::move(missingBlockIsIntegrityViolation), std::move(fuseOptions));
|
||||
}
|
||||
|
||||
void Parser::_checkValidCipher(const string &cipher, const vector<string> &supportedCiphers) {
|
||||
|
@ -8,16 +8,16 @@ using std::vector;
|
||||
using boost::optional;
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir, const optional<bf::path> &configFile,
|
||||
bool foreground, const optional<double> &unmountAfterIdleMinutes,
|
||||
const optional<bf::path> &logFile, const optional<string> &cipher,
|
||||
const optional<uint32_t> &blocksizeBytes,
|
||||
ProgramOptions::ProgramOptions(bf::path baseDir, bf::path mountDir, optional<bf::path> configFile,
|
||||
bool foreground, optional<double> unmountAfterIdleMinutes,
|
||||
optional<bf::path> logFile, optional<string> cipher,
|
||||
optional<uint32_t> blocksizeBytes,
|
||||
bool noIntegrityChecks,
|
||||
const boost::optional<bool> &missingBlockIsIntegrityViolation,
|
||||
const vector<string> &fuseOptions)
|
||||
:_baseDir(baseDir), _mountDir(mountDir), _configFile(configFile), _foreground(foreground), _noIntegrityChecks(noIntegrityChecks),
|
||||
_cipher(cipher), _blocksizeBytes(blocksizeBytes), _unmountAfterIdleMinutes(unmountAfterIdleMinutes),
|
||||
_missingBlockIsIntegrityViolation(missingBlockIsIntegrityViolation), _logFile(logFile), _fuseOptions(fuseOptions) {
|
||||
boost::optional<bool> missingBlockIsIntegrityViolation,
|
||||
vector<string> fuseOptions)
|
||||
:_baseDir(std::move(baseDir)), _mountDir(std::move(mountDir)), _configFile(std::move(configFile)), _foreground(foreground), _noIntegrityChecks(noIntegrityChecks),
|
||||
_cipher(std::move(cipher)), _blocksizeBytes(std::move(blocksizeBytes)), _unmountAfterIdleMinutes(std::move(unmountAfterIdleMinutes)),
|
||||
_missingBlockIsIntegrityViolation(std::move(missingBlockIsIntegrityViolation)), _logFile(std::move(logFile)), _fuseOptions(std::move(fuseOptions)) {
|
||||
}
|
||||
|
||||
const bf::path &ProgramOptions::baseDir() const {
|
||||
|
@ -12,15 +12,15 @@ namespace cryfs {
|
||||
namespace program_options {
|
||||
class ProgramOptions final {
|
||||
public:
|
||||
ProgramOptions(const boost::filesystem::path &baseDir, const boost::filesystem::path &mountDir,
|
||||
const boost::optional<boost::filesystem::path> &configFile,
|
||||
bool foreground, const boost::optional<double> &unmountAfterIdleMinutes,
|
||||
const boost::optional<boost::filesystem::path> &logFile,
|
||||
const boost::optional<std::string> &cipher,
|
||||
const boost::optional<uint32_t> &blocksizeBytes,
|
||||
ProgramOptions(boost::filesystem::path baseDir, boost::filesystem::path mountDir,
|
||||
boost::optional<boost::filesystem::path> configFile,
|
||||
bool foreground, boost::optional<double> unmountAfterIdleMinutes,
|
||||
boost::optional<boost::filesystem::path> logFile,
|
||||
boost::optional<std::string> cipher,
|
||||
boost::optional<uint32_t> blocksizeBytes,
|
||||
bool noIntegrityChecks,
|
||||
const boost::optional<bool> &missingBlockIsIntegrityViolation,
|
||||
const std::vector<std::string> &fuseOptions);
|
||||
boost::optional<bool> missingBlockIsIntegrityViolation,
|
||||
std::vector<std::string> fuseOptions);
|
||||
ProgramOptions(ProgramOptions &&rhs) = default;
|
||||
|
||||
const boost::filesystem::path &baseDir() const;
|
||||
|
@ -89,40 +89,40 @@ const std::string &CryConfig::RootBlob() const {
|
||||
return _rootBlob;
|
||||
}
|
||||
|
||||
void CryConfig::SetRootBlob(const std::string &value) {
|
||||
_rootBlob = value;
|
||||
void CryConfig::SetRootBlob(std::string value) {
|
||||
_rootBlob = std::move(value);
|
||||
}
|
||||
|
||||
const string &CryConfig::EncryptionKey() const {
|
||||
return _encKey;
|
||||
}
|
||||
|
||||
void CryConfig::SetEncryptionKey(const std::string &value) {
|
||||
_encKey = value;
|
||||
void CryConfig::SetEncryptionKey(std::string value) {
|
||||
_encKey = std::move(value);
|
||||
}
|
||||
|
||||
const std::string &CryConfig::Cipher() const {
|
||||
return _cipher;
|
||||
};
|
||||
|
||||
void CryConfig::SetCipher(const std::string &value) {
|
||||
_cipher = value;
|
||||
void CryConfig::SetCipher(std::string value) {
|
||||
_cipher = std::move(value);
|
||||
}
|
||||
|
||||
const std::string &CryConfig::Version() const {
|
||||
return _version;
|
||||
}
|
||||
|
||||
void CryConfig::SetVersion(const std::string &value) {
|
||||
_version = value;
|
||||
void CryConfig::SetVersion(std::string value) {
|
||||
_version = std::move(value);
|
||||
}
|
||||
|
||||
const std::string &CryConfig::CreatedWithVersion() const {
|
||||
return _createdWithVersion;
|
||||
}
|
||||
|
||||
void CryConfig::SetCreatedWithVersion(const std::string &value) {
|
||||
_createdWithVersion = value;
|
||||
void CryConfig::SetCreatedWithVersion(std::string value) {
|
||||
_createdWithVersion = std::move(value);
|
||||
}
|
||||
|
||||
uint64_t CryConfig::BlocksizeBytes() const {
|
||||
@ -137,8 +137,8 @@ const CryConfig::FilesystemID &CryConfig::FilesystemId() const {
|
||||
return _filesystemId;
|
||||
}
|
||||
|
||||
void CryConfig::SetFilesystemId(const FilesystemID &value) {
|
||||
_filesystemId = value;
|
||||
void CryConfig::SetFilesystemId(FilesystemID value) {
|
||||
_filesystemId = std::move(value);
|
||||
}
|
||||
|
||||
optional<uint32_t> CryConfig::ExclusiveClientId() const {
|
||||
|
@ -18,26 +18,26 @@ public:
|
||||
CryConfig(const CryConfig &rhs) = default;
|
||||
|
||||
const std::string &RootBlob() const;
|
||||
void SetRootBlob(const std::string &value);
|
||||
void SetRootBlob(std::string value);
|
||||
|
||||
const std::string &EncryptionKey() const;
|
||||
void SetEncryptionKey(const std::string &value);
|
||||
void SetEncryptionKey(std::string value);
|
||||
|
||||
const std::string &Cipher() const;
|
||||
void SetCipher(const std::string &value);
|
||||
void SetCipher(std::string value);
|
||||
|
||||
const std::string &Version() const;
|
||||
void SetVersion(const std::string &value);
|
||||
void SetVersion(std::string value);
|
||||
|
||||
const std::string &CreatedWithVersion() const;
|
||||
void SetCreatedWithVersion(const std::string &value);
|
||||
void SetCreatedWithVersion(std::string value);
|
||||
|
||||
uint64_t BlocksizeBytes() const;
|
||||
void SetBlocksizeBytes(uint64_t value);
|
||||
|
||||
using FilesystemID = cpputils::FixedSizeData<16>;
|
||||
const FilesystemID &FilesystemId() const;
|
||||
void SetFilesystemId(const FilesystemID &value);
|
||||
void SetFilesystemId(FilesystemID value);
|
||||
|
||||
// If the exclusive client Id is set, then additional integrity measures (i.e. treating missing blocks as integrity violations) are enabled.
|
||||
// Because this only works in a single-client setting, only this one client Id is allowed to access the file system.
|
||||
|
@ -25,7 +25,7 @@ CryConfigFile::~CryConfigFile() {
|
||||
//We do not call save() here, because we do not want the config file to be re-encrypted on each filesystem run
|
||||
}
|
||||
|
||||
optional<CryConfigFile> CryConfigFile::load(const bf::path &path, const string &password) {
|
||||
optional<CryConfigFile> CryConfigFile::load(bf::path path, const string &password) {
|
||||
auto encryptedConfigData = Data::LoadFromFile(path);
|
||||
if (encryptedConfigData == none) {
|
||||
LOG(ERROR, "Config file not found");
|
||||
@ -44,7 +44,7 @@ optional<CryConfigFile> CryConfigFile::load(const bf::path &path, const string &
|
||||
LOG(ERROR, "Inner cipher algorithm used to encrypt config file doesn't match config value");
|
||||
return none;
|
||||
}
|
||||
auto configFile = CryConfigFile(path, std::move(config), std::move(*encryptor));
|
||||
auto configFile = CryConfigFile(std::move(path), std::move(config), std::move(*encryptor));
|
||||
if (decrypted->wasInDeprecatedConfigFormat) {
|
||||
// Migrate it to new format
|
||||
configFile.save();
|
||||
@ -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, const CryConfig &config, const string &password, const SCryptSettings &scryptSettings) {
|
||||
CryConfigFile CryConfigFile::create(bf::path path, CryConfig config, const string &password, const SCryptSettings &scryptSettings) {
|
||||
if (bf::exists(path)) {
|
||||
throw std::runtime_error("Config file exists already.");
|
||||
}
|
||||
auto result = CryConfigFile(path, config, CryConfigEncryptorFactory::deriveKey(password, scryptSettings));
|
||||
auto result = CryConfigFile(std::move(path), std::move(config), CryConfigEncryptorFactory::deriveKey(password, scryptSettings));
|
||||
result.save();
|
||||
return result;
|
||||
}
|
||||
|
||||
CryConfigFile::CryConfigFile(const bf::path &path, const CryConfig &config, unique_ref<CryConfigEncryptor> encryptor)
|
||||
: _path (path), _config(config), _encryptor(std::move(encryptor)) {
|
||||
CryConfigFile::CryConfigFile(bf::path path, CryConfig config, unique_ref<CryConfigEncryptor> encryptor)
|
||||
: _path(std::move(path)), _config(std::move(config)), _encryptor(std::move(encryptor)) {
|
||||
}
|
||||
|
||||
void CryConfigFile::save() const {
|
||||
|
@ -14,15 +14,15 @@ namespace cryfs {
|
||||
CryConfigFile(CryConfigFile &&rhs) = default;
|
||||
~CryConfigFile();
|
||||
|
||||
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);
|
||||
static CryConfigFile create(boost::filesystem::path path, CryConfig config, const std::string &password, const cpputils::SCryptSettings &scryptSettings);
|
||||
static boost::optional<CryConfigFile> load(boost::filesystem::path path, const std::string &password);
|
||||
void save() const;
|
||||
|
||||
CryConfig *config();
|
||||
const CryConfig *config() const;
|
||||
|
||||
private:
|
||||
CryConfigFile(const boost::filesystem::path &path, const CryConfig &config, cpputils::unique_ref<CryConfigEncryptor> encryptor);
|
||||
CryConfigFile(boost::filesystem::path path, CryConfig config, cpputils::unique_ref<CryConfigEncryptor> encryptor);
|
||||
|
||||
boost::filesystem::path _path;
|
||||
CryConfig _config;
|
||||
|
@ -31,16 +31,16 @@ using namespace cpputils::logging;
|
||||
namespace cryfs {
|
||||
|
||||
CryConfigLoader::CryConfigLoader(shared_ptr<Console> console, RandomGenerator &keyGenerator, const SCryptSettings &scryptSettings, function<string()> askPasswordForExistingFilesystem, function<string()> askPasswordForNewFilesystem, const optional<string> &cipherFromCommandLine, const boost::optional<uint32_t> &blocksizeBytesFromCommandLine, const boost::optional<bool> &missingBlockIsIntegrityViolationFromCommandLine)
|
||||
: _console(console), _creator(console, keyGenerator), _scryptSettings(scryptSettings),
|
||||
: _console(std::move(console)), _creator(console, keyGenerator), _scryptSettings(scryptSettings),
|
||||
_askPasswordForExistingFilesystem(askPasswordForExistingFilesystem), _askPasswordForNewFilesystem(askPasswordForNewFilesystem),
|
||||
_cipherFromCommandLine(cipherFromCommandLine), _blocksizeBytesFromCommandLine(blocksizeBytesFromCommandLine),
|
||||
_missingBlockIsIntegrityViolationFromCommandLine(missingBlockIsIntegrityViolationFromCommandLine) {
|
||||
}
|
||||
|
||||
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::_loadConfig(const bf::path &filename) {
|
||||
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::_loadConfig(bf::path filename) {
|
||||
string password = _askPasswordForExistingFilesystem();
|
||||
std::cout << "Loading config file (this can take some time)..." << std::flush;
|
||||
auto config = CryConfigFile::load(filename, password);
|
||||
auto config = CryConfigFile::load(std::move(filename), password);
|
||||
if (config == none) {
|
||||
return none;
|
||||
}
|
||||
@ -101,20 +101,20 @@ void CryConfigLoader::_checkMissingBlocksAreIntegrityViolations(CryConfigFile *c
|
||||
}
|
||||
}
|
||||
|
||||
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::loadOrCreate(const bf::path &filename) {
|
||||
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::loadOrCreate(bf::path filename) {
|
||||
if (bf::exists(filename)) {
|
||||
return _loadConfig(filename);
|
||||
return _loadConfig(std::move(filename));
|
||||
} else {
|
||||
return _createConfig(filename);
|
||||
return _createConfig(std::move(filename));
|
||||
}
|
||||
}
|
||||
|
||||
CryConfigLoader::ConfigLoadResult CryConfigLoader::_createConfig(const bf::path &filename) {
|
||||
CryConfigLoader::ConfigLoadResult CryConfigLoader::_createConfig(bf::path filename) {
|
||||
auto config = _creator.create(_cipherFromCommandLine, _blocksizeBytesFromCommandLine, _missingBlockIsIntegrityViolationFromCommandLine);
|
||||
//TODO Ask confirmation if using insecure password (<8 characters)
|
||||
string password = _askPasswordForNewFilesystem();
|
||||
std::cout << "Creating config file (this can take some time)..." << std::flush;
|
||||
auto result = CryConfigFile::create(filename, std::move(config.config), password, _scryptSettings);
|
||||
auto result = CryConfigFile::create(std::move(filename), std::move(config.config), password, _scryptSettings);
|
||||
std::cout << "done" << std::endl;
|
||||
return ConfigLoadResult {std::move(result), config.myClientId};
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ public:
|
||||
uint32_t myClientId;
|
||||
};
|
||||
|
||||
boost::optional<ConfigLoadResult> loadOrCreate(const boost::filesystem::path &filename);
|
||||
boost::optional<ConfigLoadResult> loadOrCreate(boost::filesystem::path filename);
|
||||
|
||||
private:
|
||||
boost::optional<ConfigLoadResult> _loadConfig(const boost::filesystem::path &filename);
|
||||
ConfigLoadResult _createConfig(const boost::filesystem::path &filename);
|
||||
boost::optional<ConfigLoadResult> _loadConfig(boost::filesystem::path filename);
|
||||
ConfigLoadResult _createConfig(boost::filesystem::path filename);
|
||||
void _checkVersion(const CryConfig &config);
|
||||
void _checkCipher(const CryConfig &config) const;
|
||||
void _checkMissingBlocksAreIntegrityViolations(CryConfigFile *configFile, uint32_t myClientId);
|
||||
|
@ -15,8 +15,8 @@ namespace cryfs {
|
||||
constexpr size_t CryConfigEncryptor::OuterKeySize;
|
||||
constexpr size_t CryConfigEncryptor::MaxTotalKeySize;
|
||||
|
||||
CryConfigEncryptor::CryConfigEncryptor(FixedSizeData<MaxTotalKeySize> derivedKey, cpputils::Data kdfParameters)
|
||||
: _derivedKey(std::move(derivedKey)), _kdfParameters(std::move(kdfParameters)) {
|
||||
CryConfigEncryptor::CryConfigEncryptor(const FixedSizeData<MaxTotalKeySize>& derivedKey, cpputils::Data kdfParameters)
|
||||
: _derivedKey(derivedKey), _kdfParameters(std::move(kdfParameters)) {
|
||||
}
|
||||
|
||||
Data CryConfigEncryptor::encrypt(const Data &plaintext, const string &cipherName) const {
|
||||
|
@ -23,7 +23,7 @@ namespace cryfs {
|
||||
bool wasInDeprecatedConfigFormat;
|
||||
};
|
||||
|
||||
CryConfigEncryptor(cpputils::FixedSizeData<MaxTotalKeySize> derivedKey, cpputils::Data _kdfParameters);
|
||||
CryConfigEncryptor(const cpputils::FixedSizeData<MaxTotalKeySize>& derivedKey, cpputils::Data _kdfParameters);
|
||||
|
||||
cpputils::Data encrypt(const cpputils::Data &plaintext, const std::string &cipherName) const;
|
||||
boost::optional<Decrypted> decrypt(const cpputils::Data &data) const;
|
||||
|
@ -13,7 +13,7 @@ namespace cryfs {
|
||||
public:
|
||||
static constexpr size_t CONFIG_SIZE = 900; // Inner config data is grown to this size before encryption to hide its actual size
|
||||
|
||||
ConcreteInnerEncryptor(typename Cipher::EncryptionKey key);
|
||||
ConcreteInnerEncryptor(const typename Cipher::EncryptionKey& key);
|
||||
|
||||
InnerConfig encrypt(const cpputils::Data &config) const override;
|
||||
boost::optional<cpputils::Data> decrypt(const InnerConfig &innerConfig) const override;
|
||||
@ -26,8 +26,8 @@ namespace cryfs {
|
||||
};
|
||||
|
||||
template<class Cipher>
|
||||
ConcreteInnerEncryptor<Cipher>::ConcreteInnerEncryptor(typename Cipher::EncryptionKey key)
|
||||
: _key(std::move(key)) {
|
||||
ConcreteInnerEncryptor<Cipher>::ConcreteInnerEncryptor(const typename Cipher::EncryptionKey& key)
|
||||
: _key(key) {
|
||||
}
|
||||
|
||||
template<class Cipher>
|
||||
|
@ -11,8 +11,8 @@ using boost::none;
|
||||
using namespace cpputils::logging;
|
||||
|
||||
namespace cryfs {
|
||||
OuterEncryptor::OuterEncryptor(Cipher::EncryptionKey key, cpputils::Data kdfParameters)
|
||||
: _key(std::move(key)), _kdfParameters(std::move(kdfParameters)) {
|
||||
OuterEncryptor::OuterEncryptor(const Cipher::EncryptionKey& key, cpputils::Data kdfParameters)
|
||||
: _key(key), _kdfParameters(std::move(kdfParameters)) {
|
||||
}
|
||||
|
||||
OuterConfig OuterEncryptor::encrypt(const Data &plaintext) const {
|
||||
|
@ -14,7 +14,7 @@ namespace cryfs {
|
||||
using Cipher = cpputils::AES256_GCM;
|
||||
static constexpr size_t CONFIG_SIZE = 1024; // Config data is grown to this size before encryption to hide its actual size
|
||||
|
||||
OuterEncryptor(Cipher::EncryptionKey key, cpputils::Data kdfParameters);
|
||||
OuterEncryptor(const Cipher::EncryptionKey& key, cpputils::Data kdfParameters);
|
||||
|
||||
OuterConfig encrypt(const cpputils::Data &encryptedInnerConfig) const;
|
||||
boost::optional<cpputils::Data> decrypt(const OuterConfig &outerConfig) const;
|
||||
|
@ -217,8 +217,8 @@ Fuse::~Fuse() {
|
||||
_argv.clear();
|
||||
}
|
||||
|
||||
Fuse::Fuse(Filesystem *fs, const std::string &fstype, const boost::optional<std::string> &fsname)
|
||||
:_fs(fs), _mountdir(), _running(false), _fstype(fstype), _fsname(fsname) {
|
||||
Fuse::Fuse(Filesystem *fs, std::string fstype, boost::optional<std::string> fsname)
|
||||
:_fs(fs), _mountdir(), _running(false), _fstype(std::move(fstype)), _fsname(std::move(fsname)) {
|
||||
}
|
||||
|
||||
void Fuse::_logException(const std::exception &e) {
|
||||
|
@ -19,7 +19,7 @@ class Filesystem;
|
||||
|
||||
class Fuse final {
|
||||
public:
|
||||
explicit Fuse(Filesystem *fs, const std::string &fstype, const boost::optional<std::string> &fsname);
|
||||
explicit Fuse(Filesystem *fs, std::string fstype, boost::optional<std::string> fsname);
|
||||
~Fuse();
|
||||
|
||||
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
|
||||
|
Loading…
x
Reference in New Issue
Block a user