mirror of
https://github.com/vgough/encfs.git
synced 2024-11-29 03:15:07 +01:00
bd182db260
git-svn-id: http://encfs.googlecode.com/svn/trunk@99 db9cf616-1c43-0410-9cb8-a902689de0d6
54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
|
|
#include <list>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "base/config.h"
|
|
#include "base/shared_ptr.h"
|
|
#include "cipher/CipherV1.h"
|
|
#include "cipher/MemoryPool.h"
|
|
#include "cipher/testing.h"
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
#include <valgrind/memcheck.h>
|
|
#endif
|
|
|
|
using namespace encfs;
|
|
using std::list;
|
|
using std::string;
|
|
|
|
namespace {
|
|
|
|
class CipherKeyTest : public testing::Test {
|
|
protected:
|
|
virtual void SetUp() {
|
|
CipherV1::init(false);
|
|
}
|
|
};
|
|
|
|
TEST_F(CipherKeyTest, ReadWrite) {
|
|
for (auto alg : CipherV1::GetAlgorithmList()) {
|
|
auto cipher = CipherV1::New(alg.iface);
|
|
ASSERT_FALSE(!cipher);
|
|
|
|
CipherKey masterKey = cipher->newRandomKey();
|
|
CipherKey volumeKey = cipher->newRandomKey();
|
|
|
|
int encodedSize = cipher->encodedKeySize();
|
|
unsigned char *keyBuf = new unsigned char[encodedSize];
|
|
|
|
cipher->setKey(masterKey);
|
|
cipher->writeKey(volumeKey, keyBuf);
|
|
|
|
CipherKey readKey = cipher->readKey(keyBuf, true);
|
|
ASSERT_TRUE(readKey.valid());
|
|
ASSERT_TRUE(readKey == volumeKey);
|
|
ASSERT_FALSE(readKey == masterKey);
|
|
|
|
delete[] keyBuf;
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace
|