keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommandGetChallenge.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/CommandGetChallenge.hpp"
15
16#include <map>
17#include <memory>
18
19#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
20#include "keyple/core/util/ApduUtil.hpp"
21
22namespace keyple {
23namespace card {
24namespace calypso {
25namespace crypto {
26namespace legacysam {
27
28using keyple::core::util::ApduUtil;
29
30const std::map<int, const std::shared_ptr<StatusProperties>>
31 CommandGetChallenge::STATUS_TABLE = [] {
32 std::map<int, const std::shared_ptr<StatusProperties>> m(
33 Command::STATUS_TABLE);
34
35 m.insert(
36 {{0x6700,
37 std::make_shared<StatusProperties>(
38 "Incorrect Le", typeid(IllegalParameterException))}});
39
40 return m;
41 }();
42
43CommandGetChallenge::CommandGetChallenge(
44 std::shared_ptr<DtoAdapters::CommandContextDto> context,
45 int expectedResponseLength)
46: Command(CommandRef::GET_CHALLENGE, expectedResponseLength, context)
47{
48 setApduRequest(
49 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
50 context->getTargetSam()->getClassByte(),
51 getCommandRef().getInstructionByte(),
52 0,
53 0,
54 static_cast<uint8_t>(expectedResponseLength))));
55}
56
57void
58CommandGetChallenge::finalizeRequest()
59{
60 /* nothing to do */
61}
62
63bool
64CommandGetChallenge::isControlSamRequiredToFinalizeRequest() const
65{
66 return false;
67}
68
69void
70CommandGetChallenge::parseResponse(
71 std::shared_ptr<ApduResponseApi> apduResponse)
72{
73 setResponseAndCheckStatus(apduResponse);
74 getContext()->getTargetSam()->setChallenge(apduResponse->getDataOut());
75}
76
77const std::map<int, const std::shared_ptr<StatusProperties>>&
78CommandGetChallenge::getStatusTable() const
79{
80 return STATUS_TABLE;
81}
82
83} /* namespace legacysam */
84} /* namespace crypto */
85} /* namespace calypso */
86} /* namespace card */
87} /* namespace keyple */