keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
SecuritySettingAdapter.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/SecuritySettingAdapter.hpp"
15
16#include <memory>
17#include <string>
18#include <typeinfo>
19
20#include "keyple/core/util/KeypleAssert.hpp"
21#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
22
23namespace keyple {
24namespace card {
25namespace calypso {
26namespace crypto {
27namespace legacysam {
28
29using keyple::core::util::Assert;
30using keyple::core::util::cpp::exception::IllegalArgumentException;
31
32SecuritySetting&
33SecuritySettingAdapter::setControlSamResource(
34 std::shared_ptr<CardReader> samReader,
35 std::shared_ptr<LegacySam> controlSam)
36{
37 Assert::getInstance()
38 .notNull(samReader, "samReader")
39 .notNull(controlSam, "controlSam")
40 .isTrue(
41 controlSam->getProductType() != ProductType::UNKNOWN,
42 "productType");
43
44 auto proxyReader = std::dynamic_pointer_cast<ProxyReaderApi>(samReader);
45 if (!proxyReader) {
46 const CardReader& samReaderRef = *samReader;
47 throw IllegalArgumentException(
48 "Cannot cast 'samReader' to ProxyReaderApi. Actual type: "
49 + std::string(typeid(samReaderRef).name()));
50 }
51
52 auto legacySamAdapter
53 = std::dynamic_pointer_cast<LegacySamAdapter>(controlSam);
54 if (!legacySamAdapter) {
55 const LegacySam& controlSamRef = *controlSam;
56 throw IllegalArgumentException(
57 "Cannot cast 'controlSam' to LegacySamAdapter. Actual type: "
58 + std::string(typeid(controlSamRef).name()));
59 }
60
61 mControlSamReader = proxyReader;
62 mControlSam = legacySamAdapter;
63
64 return *this;
65}
66
67std::shared_ptr<ProxyReaderApi>
68SecuritySettingAdapter::getControlSamReader() const
69{
70 return mControlSamReader;
71}
72
73std::shared_ptr<LegacySamAdapter>
74SecuritySettingAdapter::getControlSam() const
75{
76 return mControlSam;
77}
78
79} /* namespace legacysam */
80} /* namespace crypto */
81} /* namespace calypso */
82} /* namespace card */
83} /* namespace keyple */