Migrate from unique_ptr to unique_ref
This commit is contained in:
parent
43d8174fd4
commit
492caeb418
@ -12,8 +12,6 @@
|
|||||||
#include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h"
|
#include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h"
|
||||||
#include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h"
|
#include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h"
|
||||||
|
|
||||||
using std::unique_ptr;
|
|
||||||
using std::make_unique;
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
//TODO Get rid of this in favor of exception hierarchy
|
//TODO Get rid of this in favor of exception hierarchy
|
||||||
@ -38,8 +36,8 @@ namespace cryfs {
|
|||||||
|
|
||||||
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
|
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
|
||||||
|
|
||||||
CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ptr<BlockStore> blockStore)
|
CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ref<BlockStore> blockStore)
|
||||||
: _blobStore(make_unique_ref<BlobStoreOnBlocks>(make_unique_ref<CachingBlockStore>(make_unique<EncryptedBlockStore<Cipher>>(std::move(blockStore), GetEncryptionKey(config.get()))), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
|
: _blobStore(make_unique_ref<BlobStoreOnBlocks>(make_unique_ref<CachingBlockStore>(make_unique_ref<EncryptedBlockStore<Cipher>>(std::move(blockStore), GetEncryptionKey(config.get()))), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Key CryDevice::GetOrCreateRootKey(CryConfig *config) {
|
Key CryDevice::GetOrCreateRootKey(CryConfig *config) {
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
using Cipher = CryConfigLoader::Cipher;
|
using Cipher = CryConfigLoader::Cipher;
|
||||||
|
|
||||||
CryDevice(cpputils::unique_ref<CryConfig> config, std::unique_ptr<blockstore::BlockStore> blockStore);
|
CryDevice(cpputils::unique_ref<CryConfig> config, cpputils::unique_ref<blockstore::BlockStore> blockStore);
|
||||||
virtual ~CryDevice();
|
virtual ~CryDevice();
|
||||||
|
|
||||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||||
|
@ -19,7 +19,7 @@ using std::make_unique;
|
|||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
auto blockStore = make_unique<OnDiskBlockStore>(bf::path("/home/heinzi/cryfstest/root"));
|
auto blockStore = make_unique_ref<OnDiskBlockStore>(bf::path("/home/heinzi/cryfstest/root"));
|
||||||
auto config = cryfs::CryConfigLoader::loadOrCreate(bf::path("/home/heinzi/cryfstest/config.json"));
|
auto config = cryfs::CryConfigLoader::loadOrCreate(bf::path("/home/heinzi/cryfstest/config.json"));
|
||||||
cryfs::CryDevice device(std::move(config), std::move(blockStore));
|
cryfs::CryDevice device(std::move(config), std::move(blockStore));
|
||||||
fspp::FilesystemImpl fsimpl(&device);
|
fspp::FilesystemImpl fsimpl(&device);
|
||||||
|
@ -14,7 +14,7 @@ using ::testing::Test;
|
|||||||
using cpputils::TempDir;
|
using cpputils::TempDir;
|
||||||
using cpputils::TempFile;
|
using cpputils::TempFile;
|
||||||
using cpputils::dynamic_pointer_move;
|
using cpputils::dynamic_pointer_move;
|
||||||
using std::make_unique;
|
using cpputils::make_unique_ref;
|
||||||
using blockstore::ondisk::OnDiskBlockStore;
|
using blockstore::ondisk::OnDiskBlockStore;
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
@ -29,27 +29,27 @@ public:
|
|||||||
|
|
||||||
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
|
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
|
||||||
{
|
{
|
||||||
CryDevice dev(CryConfigLoader::createNewWithWeakKey(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::createNewWithWeakKey(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
}
|
}
|
||||||
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
auto root = dev.Load(bf::path("/"));
|
auto root = dev.Load(bf::path("/"));
|
||||||
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
|
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
|
||||||
{
|
{
|
||||||
CryDevice dev(CryConfigLoader::createNew(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::createNew(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
}
|
}
|
||||||
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
auto root = dev.Load(bf::path("/"));
|
auto root = dev.Load(bf::path("/"));
|
||||||
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
|
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
|
||||||
{
|
{
|
||||||
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
}
|
}
|
||||||
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
||||||
auto root = dev.Load(bf::path("/"));
|
auto root = dev.Load(bf::path("/"));
|
||||||
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
: configFile(false) {}
|
: configFile(false) {}
|
||||||
|
|
||||||
unique_ref<Device> createDevice() override {
|
unique_ref<Device> createDevice() override {
|
||||||
auto blockStore = std::make_unique<FakeBlockStore>();
|
auto blockStore = cpputils::make_unique_ref<FakeBlockStore>();
|
||||||
auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path());
|
auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path());
|
||||||
return make_unique_ref<CryDevice>(std::move(config), std::move(blockStore));
|
return make_unique_ref<CryDevice>(std::move(config), std::move(blockStore));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user