14#include "keyple/card/calypso/crypto/legacysam/LegacySamExtensionService.hpp"
19#include "keyple/card/calypso/crypto/legacysam/ContextSettingAdapter.hpp"
20#include "keyple/card/calypso/crypto/legacysam/LegacySamApiFactoryAdapter.hpp"
21#include "keyple/card/calypso/crypto/legacysam/LegacySamResourceProfileExtensionAdapter.hpp"
22#include "keyple/card/calypso/crypto/legacysam/LegacySamSelectionExtensionAdapter.hpp"
23#include "keyple/core/common/CommonApiProperties.hpp"
24#include "keyple/core/util/KeypleAssert.hpp"
25#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
26#include "keypop/card/CardApiProperties.hpp"
27#include "keypop/reader/ReaderApiProperties.hpp"
35using keyple::core::util::Assert;
36using keyple::core::util::cpp::exception::IllegalArgumentException;
38std::shared_ptr<LegacySamExtensionService> LegacySamExtensionService::mInstance
41LegacySamExtensionService::LegacySamExtensionService()
42: mContextSetting(std::make_shared<ContextSettingAdapter>())
46std::shared_ptr<LegacySamExtensionService>
47LegacySamExtensionService::getInstance()
49 if (mInstance ==
nullptr) {
50 mInstance = std::shared_ptr<LegacySamExtensionService>(
51 new LegacySamExtensionService());
56std::shared_ptr<ContextSetting>
57LegacySamExtensionService::getContextSetting()
59 return mContextSetting;
62std::shared_ptr<LegacySamApiFactory>
63LegacySamExtensionService::getLegacySamApiFactory()
65 return std::make_shared<LegacySamApiFactoryAdapter>(mContextSetting);
68std::shared_ptr<CardResourceProfileExtension>
69LegacySamExtensionService::createLegacySamResourceProfileExtension(
70 std::shared_ptr<LegacySamSelectionExtension> legacySamSelectionExtension)
72 Assert::getInstance().notNull(
73 legacySamSelectionExtension,
"Legacy SAM selection");
74 auto legacySamSelectionExtensionAdapter
75 = std::dynamic_pointer_cast<LegacySamSelectionExtensionAdapter>(
76 legacySamSelectionExtension);
78 if (!legacySamSelectionExtensionAdapter) {
79 throw IllegalArgumentException(
80 "Cannot cast 'legacySamSelectionExtension' to "
81 "LegacySamSelectionExtensionAdapter");
83 return std::make_shared<LegacySamResourceProfileExtensionAdapter>(
84 legacySamSelectionExtensionAdapter,
"");
87std::shared_ptr<CardResourceProfileExtension>
88LegacySamExtensionService::createLegacySamResourceProfileExtension(
89 std::shared_ptr<LegacySamSelectionExtension> legacySamSelectionExtension,
90 const std::string& powerOnDataRegex)
92 core::util::Assert::getInstance().notEmpty(
93 powerOnDataRegex,
"powerOnDataRegex");
94 auto legacySamSelectionExtensionAdapter
95 = std::dynamic_pointer_cast<LegacySamSelectionExtensionAdapter>(
96 legacySamSelectionExtension);
97 if (!legacySamSelectionExtensionAdapter) {
98 throw IllegalArgumentException(
99 "Cannot cast 'legacySamSelectionExtension' to "
100 "LegacySamSelectionExtensionAdapter");
102 return std::make_shared<LegacySamResourceProfileExtensionAdapter>(
103 legacySamSelectionExtensionAdapter, powerOnDataRegex);
107LegacySamExtensionService::getCommonApiVersion()
const
109 return keyple::core::common::CommonApiProperties_VERSION;
113LegacySamExtensionService::getReaderApiVersion()
const
115 return keypop::reader::ReaderApiProperties_VERSION;
119LegacySamExtensionService::getCardApiVersion()
const
121 return keypop::card::CardApiProperties_VERSION;