2004-11-05 03:10:59 +00:00
|
|
|
/**
|
2005-12-23 06:05:33 +00:00
|
|
|
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
|
2004-11-05 03:10:59 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include "securearrayunittest.h"
|
2005-01-01 05:11:34 +00:00
|
|
|
#include <QtCrypto>
|
2004-11-05 03:10:59 +00:00
|
|
|
|
2005-12-23 06:05:33 +00:00
|
|
|
void SecureArrayUnitTest::initTestCase()
|
2004-11-05 03:10:59 +00:00
|
|
|
{
|
2005-12-23 06:05:33 +00:00
|
|
|
m_init = new QCA::Initializer;
|
|
|
|
#include "../fixpaths.include"
|
2004-11-05 03:10:59 +00:00
|
|
|
}
|
|
|
|
|
2005-12-23 06:05:33 +00:00
|
|
|
void SecureArrayUnitTest::cleanupTestCase()
|
2004-11-05 03:10:59 +00:00
|
|
|
{
|
2005-12-23 06:05:33 +00:00
|
|
|
delete m_init;
|
|
|
|
}
|
2004-11-05 03:10:59 +00:00
|
|
|
|
2005-12-23 06:05:33 +00:00
|
|
|
|
|
|
|
void SecureArrayUnitTest::testAll()
|
|
|
|
{
|
2004-11-05 03:10:59 +00:00
|
|
|
QSecureArray emptyArray;
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( emptyArray.size(), 0 );
|
|
|
|
QVERIFY( emptyArray.isEmpty() );
|
2004-11-05 03:10:59 +00:00
|
|
|
|
|
|
|
QSecureArray testArray(10);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( testArray.size(), 10 );
|
|
|
|
QCOMPARE( testArray.isEmpty(), false );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
2004-12-19 06:59:24 +00:00
|
|
|
QSecureArray testArray64(64);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( testArray64.size(), 64 );
|
|
|
|
QCOMPARE( testArray64.isEmpty(), false );
|
2004-12-19 06:59:24 +00:00
|
|
|
|
2004-11-05 09:41:32 +00:00
|
|
|
//testArray.fill( 'a' );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < testArray.size(); i++) {
|
2004-11-05 09:41:32 +00:00
|
|
|
testArray[ i ] = 0x61;
|
|
|
|
}
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex( testArray ), QString( "61616161616161616161" ) );
|
2004-12-19 06:59:24 +00:00
|
|
|
|
|
|
|
testArray.fill( 'b' );
|
2004-11-05 09:41:32 +00:00
|
|
|
testArray[7] = 0x00;
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex( testArray ), QString( "62626262626262006262" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
QByteArray byteArray(10, 'c');
|
2004-11-05 09:41:32 +00:00
|
|
|
QSecureArray secureArray( byteArray );
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( secureArray.size(), 10 );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
byteArray.fill( 'd' );
|
|
|
|
// it should be a copy, so no effect
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
|
|
|
QSecureArray copyArray( secureArray );
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( copyArray ), QString( "63636363636363636363" ) );
|
2004-12-19 06:59:24 +00:00
|
|
|
copyArray.fill(0x64);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( copyArray ), QString( "64646464646464646464" ) );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
|
|
|
// test for detaching
|
|
|
|
QSecureArray detachArray1 = secureArray; // currently the same
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray1 ), QString( "63636363636363636363" ) );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < detachArray1.size(); i++) {
|
2004-11-05 09:41:32 +00:00
|
|
|
detachArray1[i] = 0x66; // implicit detach
|
|
|
|
}
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray1 ), QString( "66666666666666666666" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
|
|
|
QSecureArray detachArray2 = secureArray; // currently the same
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray2 ), QString( "63636363636363636363" ) );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
//implicit detach
|
|
|
|
for (int i = 0; i < detachArray2.size(); i++) {
|
2004-11-05 09:41:32 +00:00
|
|
|
detachArray2.data()[i] = 0x67;
|
|
|
|
}
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray2 ), QString( "67676767676767676767" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
QSecureArray detachArray3 = secureArray; // implicitly shared copy
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray3 ), QString( "63636363636363636363" ) );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < detachArray3.size(); i++) {
|
2004-11-05 09:41:32 +00:00
|
|
|
detachArray3.data()[i] = 0x68;
|
|
|
|
}
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( detachArray3 ), QString( "68686868686868686868" ) );
|
2004-11-05 09:41:32 +00:00
|
|
|
|
2004-11-05 11:50:35 +00:00
|
|
|
|
|
|
|
// test for resizing
|
|
|
|
QSecureArray resizeArray = emptyArray;
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( resizeArray.size(), 0 );
|
2004-11-05 11:50:35 +00:00
|
|
|
resizeArray.resize(20);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( resizeArray.size(), 20 );
|
2004-11-05 11:50:35 +00:00
|
|
|
resizeArray.resize(40);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( resizeArray.size(), 40 );
|
2004-11-05 11:50:35 +00:00
|
|
|
resizeArray.resize(10);
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( resizeArray.size(), 10 );
|
2004-11-14 06:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
// test for append
|
|
|
|
QSecureArray appendArray = secureArray;
|
|
|
|
appendArray.append( QSecureArray() );
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex( secureArray), QCA::arrayToHex( appendArray ) );
|
2004-11-14 06:13:11 +00:00
|
|
|
appendArray.append( secureArray );
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( secureArray ), QString( "63636363636363636363" ) );
|
|
|
|
QCOMPARE( QCA::arrayToHex ( appendArray ), QString( "6363636363636363636363636363636363636363" ) );
|
2004-11-14 06:13:11 +00:00
|
|
|
QSecureArray appendArray2 = secureArray;
|
2005-12-23 06:05:33 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex ( appendArray2.append(secureArray) ), QString( "6363636363636363636363636363636363636363" ) );
|
2004-12-19 06:59:24 +00:00
|
|
|
|
|
|
|
// test for a possible problem with operator[]
|
2005-12-23 06:05:33 +00:00
|
|
|
QVERIFY( (secureArray[0] == (char)0x63) );
|
2004-11-05 03:10:59 +00:00
|
|
|
}
|
|
|
|
|
2005-12-23 06:05:33 +00:00
|
|
|
QTEST_MAIN(SecureArrayUnitTest)
|