keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommandReadParameters.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/CommandReadParameters.hpp"
15
16#include <map>
17#include <memory>
18#include <vector>
19
20#include "keyple/card/calypso/crypto/legacysam/CounterOverflowException.hpp"
21#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/LegacySamConstants.hpp"
23#include "keyple/core/util/ApduUtil.hpp"
24#include "keyple/core/util/cpp/System.hpp"
25
26namespace keyple {
27namespace card {
28namespace calypso {
29namespace crypto {
30namespace legacysam {
31
32using keyple::core::util::ApduUtil;
33using keyple::core::util::cpp::System;
34const int CommandReadParameters::SW_DATA_NOT_SIGNED_WARNING = 0x6200;
35
36const std::map<int, const std::shared_ptr<StatusProperties>>
37 CommandReadParameters::STATUS_TABLE = [] {
38 std::map<int, const std::shared_ptr<StatusProperties>> m(
39 Command::STATUS_TABLE);
40
41 m.insert(
42 {{0x6900,
43 std::make_shared<StatusProperties>(
44 "An event counter cannot be incremented",
45 typeid(CounterOverflowException))},
46 {0x6A00,
47 std::make_shared<StatusProperties>(
48 "Incorrect P1 or P2", typeid(IllegalParameterException))},
49 {0x6200,
50 std::make_shared<StatusProperties>(
51 "Correct execution with warning: data not signed")}});
52 return m;
53 }();
54
55CommandReadParameters::CommandReadParameters(
56 std::shared_ptr<DtoAdapters::CommandContextDto> context)
57: Command(CommandRef::READ_PARAMETERS, 48, context)
58{
59 const uint8_t cla = context->getTargetSam()->getClassByte();
60 const uint8_t p1 = 0x00;
61 const uint8_t p2 = 0xA0;
62
63 setApduRequest(
64 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
65 cla, getCommandRef().getInstructionByte(), p1, p2)));
66}
67
68void
69CommandReadParameters::finalizeRequest()
70{
71 /* nothing to do */
72}
73
74bool
75CommandReadParameters::isControlSamRequiredToFinalizeRequest() const
76{
77 return false;
78}
79
80void
81CommandReadParameters::parseResponse(
82 std::shared_ptr<ApduResponseApi> apduResponse)
83{
84 setResponseAndCheckStatus(apduResponse);
85 std::vector<uint8_t> keyParameter(
86 LegacySamConstants::SAM_PARAMETERS_LENGTH);
87 System::arraycopy(
88 apduResponse->getApdu(),
89 8,
90 keyParameter,
91 0,
92 LegacySamConstants::SAM_PARAMETERS_LENGTH);
93 getContext()->getTargetSam()->setSamParameters(
94 std::make_shared<SamParametersAdapter>(keyParameter));
95}
96
97const std::map<int, const std::shared_ptr<StatusProperties>>&
98CommandReadParameters::getStatusTable() const
99{
100 return STATUS_TABLE;
101}
102
103} /* namespace legacysam */
104} /* namespace crypto */
105} /* namespace calypso */
106} /* namespace card */
107} /* namespace keyple */