Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2010-09-11 21:49:30 +0400
committerFelix Geyer <debfx@fobos.de>2010-09-11 21:49:30 +0400
commit6a2034fa248385d1d1637d4c3444045e50e0c5f5 (patch)
tree7526ece1e918ea4daa1de072bab37e8d99489980 /tests/TestCryptoHash.cpp
parentf5dd24fdbecb94f07398bacbe8fd905b5c83f806 (diff)
Add crypto classes and tests. Link to libgcrypt.
Diffstat (limited to 'tests/TestCryptoHash.cpp')
-rw-r--r--tests/TestCryptoHash.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/TestCryptoHash.cpp b/tests/TestCryptoHash.cpp
new file mode 100644
index 000000000..e81d82313
--- /dev/null
+++ b/tests/TestCryptoHash.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 or (at your option)
+ * version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QtTest/QTest>
+
+#include "crypto/Crypto.h"
+#include "crypto/CryptoHash.h"
+
+class TestCryptoHash : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void initTestCase();
+ void test();
+};
+
+void TestCryptoHash::initTestCase()
+{
+ Crypto::init();
+}
+
+void TestCryptoHash::test()
+{
+ // TODO move somewhere else
+ QVERIFY(Crypto::selfTest());
+
+ CryptoHash cryptoHash1(CryptoHash::Sha256);
+ QCOMPARE(QString(cryptoHash1.result().toHex()),
+ QString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+
+ QByteArray source2 = QString("KeePassX").toAscii();
+ QString result2 = CryptoHash::hash(source2, CryptoHash::Sha256).toHex();
+ QCOMPARE(result2, QString("0b56e5f65263e747af4a833bd7dd7ad26a64d7a4de7c68e52364893dca0766b4"));
+
+ CryptoHash cryptoHash3(CryptoHash::Sha256);
+ cryptoHash3.addData(QString("KeePa").toAscii());
+ cryptoHash3.addData(QString("ssX").toAscii());
+ QCOMPARE(QString(cryptoHash3.result().toHex()),
+ QString("0b56e5f65263e747af4a833bd7dd7ad26a64d7a4de7c68e52364893dca0766b4"));
+}
+
+QTEST_MAIN(TestCryptoHash);
+
+#include "TestCryptoHash.moc"