diff options
author | angelsl <angelsl@in04.sg> | 2017-11-12 15:20:57 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2018-01-13 22:23:20 +0300 |
commit | 2e19af5032513f3041e1c8936d629b52a8737304 (patch) | |
tree | 51b87502999dd275a46cd235e0ef2e01833843cf /tests | |
parent | 6aaa89a23cb6fa7ba327aa187c0baf886f2dba71 (diff) |
Pull out KDFs into their own class hierarchy
In preparation for multiple KDFs in KDBX 4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TestKeePass1Reader.cpp | 3 | ||||
-rw-r--r-- | tests/TestKeys.cpp | 27 |
2 files changed, 18 insertions, 12 deletions
diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index f60846d26..7e015c2bc 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -26,6 +26,7 @@ #include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h" +#include "crypto/kdf/AesKdf.h" #include "format/KeePass1Reader.h" #include "format/KeePass2Reader.h" #include "format/KeePass2Writer.h" @@ -110,7 +111,7 @@ void TestKeePass1Reader::testBasic() void TestKeePass1Reader::testMasterKey() { QVERIFY(m_db->hasKey()); - QCOMPARE(m_db->transformRounds(), static_cast<quint64>(713)); + QCOMPARE(static_cast<AesKdf*>(m_db->kdf())->rounds(), static_cast<quint64>(713)); } void TestKeePass1Reader::testCustomIcons() diff --git a/tests/TestKeys.cpp b/tests/TestKeys.cpp index 95a72a49f..990878e2d 100644 --- a/tests/TestKeys.cpp +++ b/tests/TestKeys.cpp @@ -27,6 +27,7 @@ #include "core/Metadata.h" #include "core/Tools.h" #include "crypto/Crypto.h" +#include "crypto/kdf/AesKdf.h" #include "crypto/CryptoHash.h" #include "format/KeePass2Reader.h" #include "format/KeePass2Writer.h" @@ -45,21 +46,23 @@ void TestKeys::testComposite() QScopedPointer<CompositeKey> compositeKey1(new CompositeKey()); QScopedPointer<PasswordKey> passwordKey1(new PasswordKey()); QScopedPointer<PasswordKey> passwordKey2(new PasswordKey("test")); - bool ok; - QString errorString; // make sure that addKey() creates a copy of the keys compositeKey1->addKey(*passwordKey1); compositeKey1->addKey(*passwordKey2); - QByteArray transformed = compositeKey1->transform(QByteArray(32, '\0'), 1, &ok, &errorString); - QVERIFY(ok); - QCOMPARE(transformed.size(), 32); + AesKdf kdf; + kdf.setRounds(1); + QByteArray transformed1; + QVERIFY(compositeKey1->transform(kdf, transformed1)); + QCOMPARE(transformed1.size(), 32); // make sure the subkeys are copied QScopedPointer<CompositeKey> compositeKey2(compositeKey1->clone()); - QCOMPARE(compositeKey2->transform(QByteArray(32, '\0'), 1, &ok, &errorString), transformed); - QVERIFY(ok); + QByteArray transformed2; + QVERIFY(compositeKey2->transform(kdf, transformed2)); + QCOMPARE(transformed2.size(), 32); + QCOMPARE(transformed1, transformed2); QScopedPointer<CompositeKey> compositeKey3(new CompositeKey()); QScopedPointer<CompositeKey> compositeKey4(new CompositeKey()); @@ -208,10 +211,12 @@ void TestKeys::benchmarkTransformKey() QByteArray seed(32, '\x4B'); - bool ok; - QString errorString; + QByteArray result; + AesKdf kdf; + kdf.setSeed(seed); + kdf.setRounds(1e6); QBENCHMARK { - compositeKey.transform(seed, 1e6, &ok, &errorString); - } + Q_UNUSED(compositeKey.transform(kdf, result)); + }; } |