keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
LegacySamExtensionService.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/card/calypso/crypto/legacysam/LegacySamExtensionService.hpp"
15
16#include <memory>
17#include <string>
18
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"
28
29namespace keyple {
30namespace card {
31namespace calypso {
32namespace crypto {
33namespace legacysam {
34
35using keyple::core::util::Assert;
36using keyple::core::util::cpp::exception::IllegalArgumentException;
37
38std::shared_ptr<LegacySamExtensionService> LegacySamExtensionService::mInstance
39 = nullptr;
40
41LegacySamExtensionService::LegacySamExtensionService()
42: mContextSetting(std::make_shared<ContextSettingAdapter>())
43{
44}
45
46std::shared_ptr<LegacySamExtensionService>
47LegacySamExtensionService::getInstance()
48{
49 if (mInstance == nullptr) {
50 mInstance = std::shared_ptr<LegacySamExtensionService>(
51 new LegacySamExtensionService());
52 }
53 return mInstance;
54}
55
56std::shared_ptr<ContextSetting>
57LegacySamExtensionService::getContextSetting()
58{
59 return mContextSetting;
60}
61
62std::shared_ptr<LegacySamApiFactory>
63LegacySamExtensionService::getLegacySamApiFactory()
64{
65 return std::make_shared<LegacySamApiFactoryAdapter>(mContextSetting);
66}
67
68std::shared_ptr<CardResourceProfileExtension>
69LegacySamExtensionService::createLegacySamResourceProfileExtension(
70 std::shared_ptr<LegacySamSelectionExtension> legacySamSelectionExtension)
71{
72 Assert::getInstance().notNull(
73 legacySamSelectionExtension, "Legacy SAM selection");
74 auto legacySamSelectionExtensionAdapter
75 = std::dynamic_pointer_cast<LegacySamSelectionExtensionAdapter>(
76 legacySamSelectionExtension);
77
78 if (!legacySamSelectionExtensionAdapter) {
79 throw IllegalArgumentException(
80 "Cannot cast 'legacySamSelectionExtension' to "
81 "LegacySamSelectionExtensionAdapter");
82 }
83 return std::make_shared<LegacySamResourceProfileExtensionAdapter>(
84 legacySamSelectionExtensionAdapter, "");
85}
86
87std::shared_ptr<CardResourceProfileExtension>
88LegacySamExtensionService::createLegacySamResourceProfileExtension(
89 std::shared_ptr<LegacySamSelectionExtension> legacySamSelectionExtension,
90 const std::string& powerOnDataRegex)
91{
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");
101 }
102 return std::make_shared<LegacySamResourceProfileExtensionAdapter>(
103 legacySamSelectionExtensionAdapter, powerOnDataRegex);
104}
105
106const std::string
107LegacySamExtensionService::getCommonApiVersion() const
108{
109 return keyple::core::common::CommonApiProperties_VERSION;
110}
111
112const std::string
113LegacySamExtensionService::getReaderApiVersion() const
114{
115 return keypop::reader::ReaderApiProperties_VERSION;
116}
117
118const std::string
119LegacySamExtensionService::getCardApiVersion() const
120{
121 return keypop::card::CardApiProperties_VERSION;
122}
123
124} /* namespace legacysam */
125} /* namespace crypto */
126} /* namespace calypso */
127} /* namespace card */
128} /* namespace keyple */