2016-02-11 16:39:42 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cpp-utils/data/DataFixture.h>
|
|
|
|
#include <cryfs/config/crypto/outer/OuterConfig.h>
|
2015-11-11 20:58:09 +01:00
|
|
|
|
|
|
|
using cpputils::Data;
|
|
|
|
using cpputils::DataFixture;
|
2016-02-22 02:38:06 +01:00
|
|
|
using cpputils::Deserializer;
|
|
|
|
using cpputils::Serializer;
|
2015-11-11 20:58:09 +01:00
|
|
|
using boost::none;
|
|
|
|
using std::ostream;
|
|
|
|
using namespace cryfs;
|
|
|
|
|
|
|
|
// This is needed for google test
|
|
|
|
namespace boost {
|
|
|
|
ostream &operator<<(ostream &stream, const OuterConfig &) {
|
|
|
|
return stream << "OuterConfig()";
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 20:42:28 +01:00
|
|
|
#include <boost/optional/optional_io.hpp>
|
2015-11-11 20:58:09 +01:00
|
|
|
|
|
|
|
class OuterConfigTest: public ::testing::Test {
|
|
|
|
public:
|
2016-02-22 02:38:06 +01:00
|
|
|
Data kdfParameters() {
|
2015-11-11 20:58:09 +01:00
|
|
|
return DataFixture::generate(128, 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(OuterConfigTest, SomeValues) {
|
2016-02-22 02:38:06 +01:00
|
|
|
Data serialized = OuterConfig{kdfParameters(), DataFixture::generate(1024), false}.serialize();
|
2015-11-11 20:58:09 +01:00
|
|
|
OuterConfig deserialized = OuterConfig::deserialize(serialized).value();
|
2016-02-22 02:38:06 +01:00
|
|
|
EXPECT_EQ(kdfParameters(), deserialized.kdfParameters);
|
2015-11-11 20:58:09 +01:00
|
|
|
EXPECT_EQ(DataFixture::generate(1024), deserialized.encryptedInnerConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OuterConfigTest, DataEmpty) {
|
2016-02-22 02:38:06 +01:00
|
|
|
Data serialized = OuterConfig{kdfParameters(), Data(0), false}.serialize();
|
2015-11-11 20:58:09 +01:00
|
|
|
OuterConfig deserialized = OuterConfig::deserialize(serialized).value();
|
2016-02-22 02:38:06 +01:00
|
|
|
EXPECT_EQ(kdfParameters(), deserialized.kdfParameters);
|
2015-11-11 20:58:09 +01:00
|
|
|
EXPECT_EQ(Data(0), deserialized.encryptedInnerConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OuterConfigTest, KeyConfigEmpty) {
|
2016-02-22 02:38:06 +01:00
|
|
|
Data serialized = OuterConfig{Data(0), DataFixture::generate(1024), false}.serialize();
|
2015-11-11 20:58:09 +01:00
|
|
|
OuterConfig deserialized = OuterConfig::deserialize(serialized).value();
|
2016-02-22 02:38:06 +01:00
|
|
|
EXPECT_EQ(Data(0), deserialized.kdfParameters);
|
2015-11-11 20:58:09 +01:00
|
|
|
EXPECT_EQ(DataFixture::generate(1024), deserialized.encryptedInnerConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OuterConfigTest, DataAndKeyConfigEmpty) {
|
2016-02-22 02:38:06 +01:00
|
|
|
Data serialized = OuterConfig{Data(0), Data(0), false}.serialize();
|
2015-11-11 20:58:09 +01:00
|
|
|
OuterConfig deserialized = OuterConfig::deserialize(serialized).value();
|
2016-02-22 02:38:06 +01:00
|
|
|
EXPECT_EQ(Data(0), deserialized.kdfParameters);
|
2015-11-11 20:58:09 +01:00
|
|
|
EXPECT_EQ(Data(0), deserialized.encryptedInnerConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OuterConfigTest, InvalidSerialization) {
|
|
|
|
auto deserialized = OuterConfig::deserialize(DataFixture::generate(1024));
|
|
|
|
EXPECT_EQ(none, deserialized);
|
|
|
|
}
|