Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ CardReaderObserver::onReaderEvent(

} catch (const std::exception& e) {
mLogger->error(
"%Transaction failed with exception: %%\n",
"%Transaction failed with exception: % %\n",
ANSI_RED,
e.what(),
ANSI_RESET);
Expand Down Expand Up @@ -188,8 +188,8 @@ CardReaderObserver::onReaderObservationError(
const std::string& readerName,
const std::shared_ptr<std::exception> e) {
mLogger->error(
"An exception occurred in plugin '%', reader '%'\n",
"An exception occurred in plugin '%', reader '%': %\n",
pluginName,
readerName,
e);
e ? e->what() : "unknown");
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
******************************************************************************/

#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -28,10 +29,9 @@
#include "keyple/core/util/cpp/Logger.hpp"
#include "keyple/core/util/cpp/LoggerFactory.hpp"
#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp"
#include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp"
#include "keyple/plugin/pcsc/PcscReader.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp"
#include "keypop/calypso/card/CalypsoCardApiFactory.hpp"
#include "keypop/calypso/card/WriteAccessLevel.hpp"
#include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp"
Expand All @@ -58,10 +58,9 @@
using keyple::core::util::cpp::Logger;
using keyple::core::util::cpp::LoggerFactory;
using keyple::core::util::cpp::exception::IllegalStateException;
using keyple::plugin::pcsc::PcscCardCommunicationProtocol;
using keyple::plugin::pcsc::PcscPluginFactoryBuilder;
using keyple::plugin::pcsc::PcscReader;
using keyple::plugin::pcsc::PcscSupportedContactlessProtocol;
using keyple::plugin::pcsc::PcscSupportedContactProtocol;
using keypop::calypso::card::CalypsoCardApiFactory;
using keypop::calypso::card::WriteAccessLevel;
using keypop::calypso::card::card::CalypsoCardSelectionExtension;
Expand Down Expand Up @@ -96,7 +95,7 @@
static std::string samReaderRegex = SAM_READER_NAME_REGEX;

/** AID: Keyple test kit profile 1, Application 2 */
static const std::string AID = "315449432E49434131";
static const std::string AID = "A000000291FF9101";

static std::string cardAid = AID;

Expand Down Expand Up @@ -127,8 +126,8 @@
"equivalent to -a=\""
<< AID << "\" -c=\"" << CARD_READER_NAME_REGEX << "\" -s=\""
<< SAM_READER_NAME_REGEX << "\")" << std::endl;
std::cout << " -a, --aid=\"APPLICATION_AID\" between 5 and 16 hex "
"bytes (e.g. \"315449432E49434131\")"
"bytes (e.g. \"A000000291FF9101\")"

Check warning on line 130 in Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/Main_SessionTrace_TN313_Pcsc.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Convert this string literal to a raw string literal.

See more on https://sonarcloud.io/project/issues?id=eclipse-keyple_keyple-cpp-example&issues=AaCQrGEWyyKf7W-fw9lG&open=AaCQrGEWyyKf7W-fw9lG&pullRequest=10
<< std::endl;
std::cout << " -c, --card=\"CARD_READER_REGEX\" regular expression "
"matching the card reader name (e.g. \"ASK Logo.*\")"
Expand Down Expand Up @@ -218,7 +217,7 @@
true,
PcscReader::IsoProtocol::T1,
PcscReader::SharingMode::SHARED,
PcscSupportedContactlessProtocol::ISO_14443_4.getName(),
PcscCardCommunicationProtocol::ISO_14443_4.getName(),
ISO_CARD_PROTOCOL);
}

Expand All @@ -233,7 +232,7 @@
false,
PcscReader::IsoProtocol::ANY,
PcscReader::SharingMode::SHARED,
PcscSupportedContactProtocol::ISO_7816_3_T0.getName(),
PcscCardCommunicationProtocol::ISO_7816_3.getName(),
SAM_PROTOCOL);
}

Expand Down Expand Up @@ -303,8 +302,8 @@
symmetricCryptoSecuritySetting->initCryptoContextForNextTransaction();
}

int
main(int argc, char** argv) {
static int
runExample(int argc, char** argv) {
parseCommandLine(argc, argv);

logger->info(
Expand Down Expand Up @@ -381,3 +380,14 @@

return 0;
}

int
main(int argc, char** argv) {
try {
return runExample(argc, argv);

} catch (const std::exception& e) {
logger->error("Example terminated on exception: %\n", e.what());
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
******************************************************************************/

#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
Expand Down Expand Up @@ -457,8 +458,8 @@ getInput() {
return static_cast<char>(getchar());
}

int
main() {
static int
runExample() {
/* Initialize the context */
initKeypleService();
initLegacySamExtensionService();
Expand Down Expand Up @@ -497,3 +498,14 @@ main() {

return 0;
}

int
main() {
try {
return runExample();

} catch (const std::exception& e) {
logger->error("Example terminated on exception: %\n", e.what());
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -29,10 +30,9 @@
#include "keyple/core/util/cpp/Logger.hpp"
#include "keyple/core/util/cpp/LoggerFactory.hpp"
#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp"
#include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp"
#include "keyple/plugin/pcsc/PcscReader.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp"
#include "keypop/calypso/card/CalypsoCardApiFactory.hpp"
#include "keypop/calypso/card/WriteAccessLevel.hpp"
#include "keypop/calypso/card/card/CalypsoCard.hpp"
Expand Down Expand Up @@ -64,10 +64,9 @@ using keyple::core::util::HexUtil;
using keyple::core::util::cpp::Logger;
using keyple::core::util::cpp::LoggerFactory;
using keyple::core::util::cpp::exception::IllegalStateException;
using keyple::plugin::pcsc::PcscCardCommunicationProtocol;
using keyple::plugin::pcsc::PcscPluginFactoryBuilder;
using keyple::plugin::pcsc::PcscReader;
using keyple::plugin::pcsc::PcscSupportedContactlessProtocol;
using keyple::plugin::pcsc::PcscSupportedContactProtocol;
using keypop::calypso::card::CalypsoCardApiFactory;
using keypop::calypso::card::WriteAccessLevel;
using keypop::calypso::card::card::CalypsoCard;
Expand Down Expand Up @@ -108,7 +107,7 @@ static const std::string samReaderRegex
= ConfigurationUtil::SAM_READER_NAME_REGEX;

/** AID: Keyple test kit profile 1, Application 2 */
static const std::string cardAid = "315449432E49434131";
static const std::string cardAid = "A000000291FF9101";

static const int counterDecrement = 1;
static const std::vector<std::uint8_t> newEventRecord(
Expand Down Expand Up @@ -162,7 +161,7 @@ initCardReader() {
true,
PcscReader::IsoProtocol::T1,
PcscReader::SharingMode::SHARED,
PcscSupportedContactlessProtocol::ISO_14443_4.getName(),
PcscCardCommunicationProtocol::ISO_14443_4.getName(),
ConfigurationUtil::ISO_CARD_PROTOCOL);
}

Expand All @@ -177,7 +176,7 @@ initSamReader() {
false,
PcscReader::IsoProtocol::ANY,
PcscReader::SharingMode::SHARED,
PcscSupportedContactProtocol::ISO_7816_3_T0.getName(),
PcscCardCommunicationProtocol::ISO_7816_3.getName(),
ConfigurationUtil::SAM_PROTOCOL);
}

Expand Down Expand Up @@ -275,8 +274,8 @@ selectCard(std::shared_ptr<CardReader> reader, const std::string& aid) {
return std::dynamic_pointer_cast<CalypsoCard>(card);
}

int
main() {
static int
runExample() {
logger->info(
"%=============== Performance measurement: validation transaction "
"===============\n",
Expand Down Expand Up @@ -423,7 +422,7 @@ main() {
->initCryptoContextForNextTransaction();
} catch (const std::exception& e) {
logger->info(
"%Transaction failed with exception: %s %\n",
"%Transaction failed with exception: % %\n",
ANSI_RED,
e.what(),
ANSI_RESET);
Expand All @@ -437,3 +436,14 @@ main() {

return 0;
}

int
main() {
try {
return runExample();

} catch (const std::exception& e) {
logger->error("Example terminated on exception: %\n", e.what());
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -29,10 +30,9 @@
#include "keyple/core/util/cpp/Logger.hpp"
#include "keyple/core/util/cpp/LoggerFactory.hpp"
#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp"
#include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp"
#include "keyple/plugin/pcsc/PcscReader.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp"
#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp"
#include "keypop/calypso/card/CalypsoCardApiFactory.hpp"
#include "keypop/calypso/card/WriteAccessLevel.hpp"
#include "keypop/calypso/card/card/CalypsoCard.hpp"
Expand Down Expand Up @@ -64,10 +64,9 @@ using keyple::core::util::HexUtil;
using keyple::core::util::cpp::Logger;
using keyple::core::util::cpp::LoggerFactory;
using keyple::core::util::cpp::exception::IllegalStateException;
using keyple::plugin::pcsc::PcscCardCommunicationProtocol;
using keyple::plugin::pcsc::PcscPluginFactoryBuilder;
using keyple::plugin::pcsc::PcscReader;
using keyple::plugin::pcsc::PcscSupportedContactlessProtocol;
using keyple::plugin::pcsc::PcscSupportedContactProtocol;
using keypop::calypso::card::CalypsoCardApiFactory;
using keypop::calypso::card::WriteAccessLevel;
using keypop::calypso::card::card::CalypsoCard;
Expand Down Expand Up @@ -109,7 +108,7 @@ static const std::string samReaderRegex
= ConfigurationUtil::SAM_READER_NAME_REGEX;

/** AID: Keyple test kit profile 1, Application 2 */
static const std::string cardAid = "315449432E49434131";
static const std::string cardAid = "A000000291FF9101";

static const int counterIncrement = 1;
static const std::vector<std::uint8_t> newContractListRecord(
Expand Down Expand Up @@ -165,7 +164,7 @@ initCardReader() {
true,
PcscReader::IsoProtocol::T1,
PcscReader::SharingMode::SHARED,
PcscSupportedContactlessProtocol::ISO_14443_4.getName(),
PcscCardCommunicationProtocol::ISO_14443_4.getName(),
ConfigurationUtil::ISO_CARD_PROTOCOL);
}

Expand All @@ -180,7 +179,7 @@ initSamReader() {
false,
PcscReader::IsoProtocol::ANY,
PcscReader::SharingMode::SHARED,
PcscSupportedContactProtocol::ISO_7816_3_T0.getName(),
PcscCardCommunicationProtocol::ISO_7816_3.getName(),
ConfigurationUtil::SAM_PROTOCOL);
}

Expand Down Expand Up @@ -278,8 +277,8 @@ selectCard(std::shared_ptr<CardReader> reader, const std::string& aid) {
return std::dynamic_pointer_cast<CalypsoCard>(card);
}

int
main() {
static int
runExample() {
logger->info(
"%=============== Performance measurement: validation transaction "
"===============\n",
Expand Down Expand Up @@ -415,7 +414,7 @@ main() {
ANSI_RESET);
} catch (const std::exception& e) {
logger->info(
"%Transaction failed with exception: %s %\n",
"%Transaction failed with exception: % %\n",
ANSI_RED,
e.what(),
ANSI_RESET);
Expand All @@ -429,3 +428,14 @@ main() {

return 0;
}

int
main() {
try {
return runExample();

} catch (const std::exception& e) {
logger->error("Example terminated on exception: %\n", e.what());
return 1;
}
}
Loading
Loading