#ifndef MESSMER_CRYFS_TEST_CRYFS_FILESYSTEM_CRYTESTBASE_H #define MESSMER_CRYFS_TEST_CRYFS_FILESYSTEM_CRYTESTBASE_H #include #include #include #include #include #include "../../testutils/TestWithFakeHomeDirectory.h" #include "../../testutils/MockConsole.h" inline auto failOnIntegrityViolation() { return [] { EXPECT_TRUE(false); }; } class CryTestBase : public TestWithFakeHomeDirectory { public: CryTestBase(): _tempLocalStateDir(), _localStateDir(_tempLocalStateDir.path()), _configFile(false), _device(nullptr) { auto fakeBlockStore = cpputils::make_unique_ref(); _device = std::make_unique(configFile(), std::move(fakeBlockStore), _localStateDir, 0x12345678, false, false, failOnIntegrityViolation()); _device->setContext(fspp::Context { fspp::relatime() }); } std::shared_ptr configFile() { cryfs::CryConfig config; config.SetCipher("aes-256-gcm"); config.SetEncryptionKey(cpputils::AES256_GCM::EncryptionKey::CreateKey(cpputils::Random::PseudoRandom(), cpputils::AES256_GCM::KEYSIZE).ToString()); config.SetBlocksizeBytes(10240); cryfs::CryPresetPasswordBasedKeyProvider keyProvider("mypassword", cpputils::make_unique_ref(cpputils::SCrypt::TestSettings)); return cryfs::CryConfigFile::create(_configFile.path(), std::move(config), &keyProvider); } cryfs::CryDevice &device() { return *_device; } private: cpputils::TempDir _tempLocalStateDir; cryfs::LocalStateDir _localStateDir; cpputils::TempFile _configFile; std::unique_ptr _device; }; #endif