Refactor Kdf class, remove fields concept

This commit is contained in:
Janek Bevendorff 2017-12-16 18:36:42 +01:00 committed by Jonathan White
parent d00ccd2eb5
commit 15648991fc
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
17 changed files with 282 additions and 474 deletions

View file

@ -33,7 +33,6 @@
#include "format/KeePass2Writer.h"
#include "keys/PasswordKey.h"
#include "keys/FileKey.h"
#include "keys/CompositeKey.h"
QHash<Uuid, Database*> Database::m_uuidMap;
@ -45,7 +44,7 @@ Database::Database()
{
m_data.cipher = KeePass2::CIPHER_AES;
m_data.compressionAlgo = CompressionGZip;
m_data.kdf = new AesKdf();
m_data.kdf = QSharedPointer<AesKdf>::create();
m_data.kdf->randomizeTransformSalt();
m_data.hasKey = false;
@ -485,23 +484,18 @@ QString Database::saveToFile(QString filePath)
}
}
Kdf* Database::kdf() const {
QSharedPointer<Kdf> Database::kdf() const
{
return m_data.kdf;
}
void Database::setKdf(Kdf* kdf) {
if (m_data.kdf == kdf) {
return;
}
if (m_data.kdf != nullptr) {
delete m_data.kdf;
}
m_data.kdf = kdf;
void Database::setKdf(QSharedPointer<Kdf> kdf)
{
m_data.kdf = std::move(kdf);
}
bool Database::changeKdf(Kdf* kdf) {
bool Database::changeKdf(QSharedPointer<Kdf> kdf)
{
kdf->randomizeTransformSalt();
QByteArray transformedMasterKey;
if (!m_data.key.transform(*kdf, transformedMasterKey)) {
@ -514,8 +508,3 @@ bool Database::changeKdf(Kdf* kdf) {
return true;
}
Database::DatabaseData::~DatabaseData()
{
delete kdf;
}