Keyple Card Calypso C++ Library - 3.2.2
Component of the Keyple C++ middleware
CommandGetDataCardPublicKey.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2023 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information
5 * regarding * copyright ownership.
6 * *
7 * *
8 * This program and the accompanying materials are made available under the
9 * terms of the Eclipse *
10 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
11 * *
12 * SPDX-License-Identifier: EPL-2.0 *
13 **************************************************************************************************/
14
15#include "keyple/card/calypso/CommandGetDataCardPublicKey.hpp"
16
17#include <map>
18#include <memory>
19
20#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
21#include "keyple/card/calypso/CalypsoCardConstant.hpp"
22#include "keyple/card/calypso/CardDataAccessException.hpp"
23#include "keyple/core/util/ApduUtil.hpp"
24#include "keyple/core/util/cpp/Arrays.hpp"
25#include "keyple/core/util/cpp/System.hpp"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30
31using keyple::core::util::ApduUtil;
32using keyple::core::util::cpp::Arrays;
33using keyple::core::util::cpp::System;
34
35const std::map<int, const std::shared_ptr<Command::StatusProperties>>
36 CommandGetDataCardPublicKey::STATUS_TABLE = [] {
37 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
38 Command::STATUS_TABLE);
39
40 m.insert(
41 {{0x6A88,
42 std::make_shared<StatusProperties>(
43 "Data object not found (optional mode not available)",
44 typeid(CardDataAccessException))},
45 {0x6B00,
46 std::make_shared<StatusProperties>(
47 "P1 or P2 value not supported",
48 typeid(CardDataAccessException))}});
49 return m;
50 }();
51
52CommandGetDataCardPublicKey::CommandGetDataCardPublicKey(
53 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
54 transactionContext,
55 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext)
56: Command(CardCommandRef::GET_DATA, nullptr, transactionContext, commandContext)
57{
58 const std::uint8_t cardClass
59 = transactionContext->getCard() != nullptr
60 ? transactionContext->getCard()->getCardClass().getValue()
61 : CalypsoCardClass::ISO.getValue();
62
63 /* APDU Case 2 - always outside secure session */
64 setApduRequest(
65 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
66 cardClass,
67 getCommandRef().getInstructionByte(),
68 CalypsoCardConstant::TAG_CARD_PUBLIC_KEY_MSB,
69 CalypsoCardConstant::TAG_CARD_PUBLIC_KEY_LSB)));
70
71 addSubName("ECC_PUBLIC_KEY");
72}
73
74void
75CommandGetDataCardPublicKey::finalizeRequest()
76{
77 /* NOP */
78}
79
80bool
81CommandGetDataCardPublicKey::isCryptoServiceRequiredToFinalizeRequest() const
82{
83 return false;
84}
85
86bool
87CommandGetDataCardPublicKey::synchronizeCryptoServiceBeforeCardProcessing()
88{
89 return true;
90}
91
92void
93CommandGetDataCardPublicKey::parseResponse(
94 std::shared_ptr<ApduResponseApi> apduResponse)
95{
96 Command::setApduResponseAndCheckStatus(apduResponse);
97
98 getTransactionContext()->getCard()->setCardPublicKey(
99 Arrays::copyOfRange(
100 apduResponse->getDataOut(),
101 CalypsoCardConstant::TAG_CARD_PUBLIC_KEY_HEADER_SIZE,
102 apduResponse->getDataOut().size()));
103}
104
105const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
106CommandGetDataCardPublicKey::getStatusTable() const
107{
108 return STATUS_TABLE;
109}
110
111} /* namespace calypso */
112} /* namespace card */
113} /* namespace keyple */