2015-10-24 01:57:17 +02:00
|
|
|
#include <google/gtest/gtest.h>
|
|
|
|
#include "../../../src/config/crypto/DerivedKeyConfig.h"
|
|
|
|
#include <messmer/cpp-utils/data/DataFixture.h>
|
2015-10-24 12:25:49 +02:00
|
|
|
#include <sstream>
|
2015-10-24 01:57:17 +02:00
|
|
|
|
|
|
|
using namespace cryfs;
|
|
|
|
using cpputils::DataFixture;
|
|
|
|
using cpputils::Data;
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
class DerivedKeyConfigTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
DerivedKeyConfig SaveAndLoad(const DerivedKeyConfig &source) {
|
2015-10-25 11:33:30 +01:00
|
|
|
Data serialized = source.save();
|
|
|
|
return DerivedKeyConfig::load(serialized).value();
|
2015-10-24 12:25:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, Salt) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), cfg.salt());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, Salt_Move) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), moved.salt());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, Salt_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), loaded.salt());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, N) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
|
|
|
EXPECT_EQ(1024, cfg.N());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, N_Move) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
|
|
|
EXPECT_EQ(1024, moved.N());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, N_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
|
|
|
EXPECT_EQ(1024, loaded.N());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, r) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
|
|
|
EXPECT_EQ(8, cfg.r());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, r_Move) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
|
|
|
EXPECT_EQ(8, moved.r());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, r_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
|
|
|
EXPECT_EQ(8, loaded.r());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, p) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
|
|
|
EXPECT_EQ(16, cfg.p());
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:25:49 +02:00
|
|
|
TEST_F(DerivedKeyConfigTest, p_Move) {
|
2015-10-24 01:57:17 +02:00
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
|
|
|
EXPECT_EQ(16, moved.p());
|
|
|
|
}
|
2015-10-24 12:25:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, p_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
|
|
|
EXPECT_EQ(16, loaded.p());
|
|
|
|
}
|