2010-09-11 13:49:30 -04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-21 17:06:30 -05:00
|
|
|
#include "TestCryptoHash.h"
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QTest>
|
2010-09-11 13:49:30 -04:00
|
|
|
|
2012-01-01 16:04:27 -05:00
|
|
|
#include "tests.h"
|
2010-09-11 13:49:30 -04:00
|
|
|
#include "crypto/Crypto.h"
|
|
|
|
#include "crypto/CryptoHash.h"
|
|
|
|
|
2014-05-16 06:32:52 -04:00
|
|
|
QTEST_GUILESS_MAIN(TestCryptoHash)
|
|
|
|
|
2010-09-11 13:49:30 -04:00
|
|
|
void TestCryptoHash::initTestCase()
|
|
|
|
{
|
2014-06-15 05:17:40 -04:00
|
|
|
QVERIFY(Crypto::init());
|
2010-09-11 13:49:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestCryptoHash::test()
|
|
|
|
{
|
|
|
|
CryptoHash cryptoHash1(CryptoHash::Sha256);
|
2010-09-19 14:13:23 -04:00
|
|
|
QCOMPARE(cryptoHash1.result(),
|
|
|
|
QByteArray::fromHex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
2010-09-11 13:49:30 -04:00
|
|
|
|
2013-11-24 15:19:20 -05:00
|
|
|
QByteArray source2 = QString("KeePassX").toLatin1();
|
2010-09-19 14:13:23 -04:00
|
|
|
QByteArray result2 = CryptoHash::hash(source2, CryptoHash::Sha256);
|
|
|
|
QCOMPARE(result2, QByteArray::fromHex("0b56e5f65263e747af4a833bd7dd7ad26a64d7a4de7c68e52364893dca0766b4"));
|
2010-09-11 13:49:30 -04:00
|
|
|
|
|
|
|
CryptoHash cryptoHash3(CryptoHash::Sha256);
|
2013-11-24 15:19:20 -05:00
|
|
|
cryptoHash3.addData(QString("KeePa").toLatin1());
|
|
|
|
cryptoHash3.addData(QString("ssX").toLatin1());
|
2010-09-19 14:13:23 -04:00
|
|
|
QCOMPARE(cryptoHash3.result(),
|
|
|
|
QByteArray::fromHex("0b56e5f65263e747af4a833bd7dd7ad26a64d7a4de7c68e52364893dca0766b4"));
|
2010-09-11 13:49:30 -04:00
|
|
|
}
|