AusweisApp2/test/qt/card/asn1/test_SecurityInfos.cpp

129 lines
3 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
* \brief Unit tests for \ref SecurityInfos
*
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2015-2018 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include <QtCore>
#include <QtTest>
#include "asn1/ChipAuthenticationInfo.h"
2019-01-03 15:06:22 +01:00
#include "asn1/PaceInfo.h"
2017-07-03 09:30:10 +02:00
#include "asn1/SecurityInfos.h"
using namespace governikus;
class test_SecurityInfos
: public QObject
{
Q_OBJECT
private Q_SLOTS:
void parseCrap()
{
QVERIFY(SecurityInfos::decode("06020400") == nullptr);
}
void emmptySet()
{
QByteArray hexString("3100");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos != nullptr);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getSecurityInfos().size(), 0);
2017-07-03 09:30:10 +02:00
}
void setWithUnknownElement()
{
QByteArray hexString("31 03"
" 020101");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos == nullptr);
}
2019-01-03 15:06:22 +01:00
void setWithPaceInfo()
2017-07-03 09:30:10 +02:00
{
QByteArray hexString("31 14"
" 30 12"
" 06 0A 04007F00070202040202"
" 02 01 02"
" 02 01 08");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos != nullptr);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getSecurityInfos().size(), 1);
2019-01-03 15:06:22 +01:00
QCOMPARE(securityInfos->getPaceInfos().size(), 1);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getChipAuthenticationInfos().size(), 0);
2017-07-03 09:30:10 +02:00
}
void setWithChipAuthenticationInfo()
{
QByteArray hexString("31 14"
" 30 12"
" 06 0A 04007F00070202030202"
" 02 01 02"
" 02 01 08");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos != nullptr);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getSecurityInfos().size(), 1);
2019-01-03 15:06:22 +01:00
QCOMPARE(securityInfos->getPaceInfos().size(), 0);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getChipAuthenticationInfos().size(), 1);
2017-07-03 09:30:10 +02:00
}
void setWithManySecurityInfos()
{
QByteArray hexString("31 3C"
" 30 12"
" 06 0A 04007F00070202030202"
" 02 01 02"
" 02 01 08"
" 30 12"
" 06 0A 04007F00070202040202"
" 02 01 02"
" 02 01 08"
" 30 12"
" 06 0A 04007F000702020F0F0F"
" 02 01 02"
" 02 01 08");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos != nullptr);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getSecurityInfos().size(), 3);
2019-01-03 15:06:22 +01:00
QCOMPARE(securityInfos->getPaceInfos().size(), 1);
2017-07-03 09:33:28 +02:00
QCOMPARE(securityInfos->getChipAuthenticationInfos().size(), 1);
2017-07-03 09:30:10 +02:00
}
void getContentBytes()
{
QByteArray hexString("31 14"
" 30 12"
" 06 0A 04007F00070202030202"
" 02 01 02"
" 02 01 08");
auto securityInfos = SecurityInfos::fromHex(hexString);
QVERIFY(securityInfos != nullptr);
QCOMPARE(securityInfos->getContentBytes(), QByteArray::fromHex(hexString));
}
};
QTEST_GUILESS_MAIN(test_SecurityInfos)
#include "test_SecurityInfos.moc"