47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
#pragma once
|
|
#ifndef MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGFILE_H
|
|
#define MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGFILE_H
|
|
|
|
#include <boost/optional.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include "CryConfig.h"
|
|
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
|
|
#include "crypto/CryConfigEncryptorFactory.h"
|
|
|
|
namespace cryfs {
|
|
class CryConfigFile final {
|
|
public:
|
|
CryConfigFile(CryConfigFile &&rhs) = default;
|
|
~CryConfigFile();
|
|
|
|
template<class SCryptConfig>
|
|
static CryConfigFile create(const boost::filesystem::path &path, CryConfig config, const std::string &password);
|
|
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);
|
|
|
|
boost::filesystem::path _path;
|
|
CryConfig _config;
|
|
cpputils::unique_ref<CryConfigEncryptor> _encryptor;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CryConfigFile);
|
|
};
|
|
|
|
template<class SCryptSettings>
|
|
CryConfigFile CryConfigFile::create(const boost::filesystem::path &path, CryConfig config, const std::string &password) {
|
|
using ConfigCipher = blockstore::encrypted::AES256_GCM; // TODO Take cipher from config instead
|
|
if (boost::filesystem::exists(path)) {
|
|
throw std::runtime_error("Config file exists already.");
|
|
}
|
|
auto result = CryConfigFile(path, std::move(config), CryConfigEncryptorFactory::deriveKey<ConfigCipher, SCryptSettings>(password, "aes-256-gcm")); // TODO Take cipher from config instead
|
|
result.save();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endif
|