mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Minor improvements in CompositeKey and TestKeys.
This commit is contained in:
parent
f82de78861
commit
0ad4b3d8fe
@ -33,7 +33,7 @@ CompositeKey::CompositeKey(const CompositeKey& key)
|
||||
|
||||
CompositeKey::~CompositeKey()
|
||||
{
|
||||
qDeleteAll(m_keys);
|
||||
clear();
|
||||
}
|
||||
|
||||
void CompositeKey::clear()
|
||||
@ -51,8 +51,8 @@ CompositeKey& CompositeKey::operator=(const CompositeKey& key)
|
||||
{
|
||||
clear();
|
||||
|
||||
Q_FOREACH (Key* subKey, key.m_keys) {
|
||||
m_keys.append(subKey->clone());
|
||||
Q_FOREACH (const Key* subKey, key.m_keys) {
|
||||
addKey(*subKey);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -62,7 +62,7 @@ QByteArray CompositeKey::rawKey() const
|
||||
{
|
||||
CryptoHash cryptoHash(CryptoHash::Sha256);
|
||||
|
||||
Q_FOREACH (Key* key, m_keys) {
|
||||
Q_FOREACH (const Key* key, m_keys) {
|
||||
cryptoHash.addData(key->rawKey());
|
||||
}
|
||||
|
||||
@ -86,9 +86,11 @@ QByteArray CompositeKey::transform(const QByteArray& seed, int rounds) const
|
||||
return CryptoHash::hash(transformed, CryptoHash::Sha256);
|
||||
}
|
||||
|
||||
QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds) {
|
||||
QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray& seed,
|
||||
int rounds) {
|
||||
QByteArray iv(16, 0);
|
||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Encrypt, seed, iv);
|
||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb,
|
||||
SymmetricCipher::Encrypt, seed, iv);
|
||||
|
||||
QByteArray result = key;
|
||||
|
||||
|
@ -37,7 +37,8 @@ public:
|
||||
void addKey(const Key& key);
|
||||
|
||||
private:
|
||||
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds);
|
||||
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed,
|
||||
int rounds);
|
||||
|
||||
QList<Key*> m_keys;
|
||||
};
|
||||
|
@ -42,27 +42,32 @@ void TestKeys::testComposite()
|
||||
PasswordKey* passwordKey1 = new PasswordKey();
|
||||
PasswordKey* passwordKey2 = new PasswordKey("test");
|
||||
|
||||
// make sure that addKey() creates a copy of the keys
|
||||
compositeKey1->addKey(*passwordKey1);
|
||||
compositeKey1->addKey(*passwordKey2);
|
||||
delete passwordKey1;
|
||||
delete passwordKey2;
|
||||
|
||||
QVERIFY(compositeKey1->transform(QByteArray(32, '\0'), 1).size() == 32);
|
||||
QByteArray transformed = compositeKey1->transform(QByteArray(32, '\0'), 1);
|
||||
QCOMPARE(transformed.size(), 32);
|
||||
|
||||
// make sure the subkeys are copied
|
||||
CompositeKey* compositeKey2 = compositeKey1->clone();
|
||||
delete compositeKey1;
|
||||
|
||||
QVERIFY(compositeKey2->transform(QByteArray(32, '\0'), 1).size() == 32);
|
||||
|
||||
QCOMPARE(compositeKey2->transform(QByteArray(32, '\0'), 1), transformed);
|
||||
delete compositeKey2;
|
||||
|
||||
CompositeKey* compositeKey3 = new CompositeKey();
|
||||
CompositeKey* compositeKey4 = new CompositeKey();
|
||||
|
||||
// test clear()
|
||||
compositeKey3->addKey(PasswordKey("test"));
|
||||
compositeKey3->clear();
|
||||
QCOMPARE(compositeKey3->rawKey(), compositeKey4->rawKey());
|
||||
|
||||
// test assignment operator
|
||||
compositeKey3->addKey(PasswordKey("123"));
|
||||
*compositeKey4 = *compositeKey3;
|
||||
QCOMPARE(compositeKey3->rawKey(), compositeKey4->rawKey());
|
||||
|
||||
delete compositeKey3;
|
||||
|
Loading…
Reference in New Issue
Block a user