14#include "keyple/card/calypso/crypto/legacysam/CommandGetData.hpp"
21#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
23#include "keyple/core/util/ApduUtil.hpp"
24#include "keyple/core/util/cpp/Arrays.hpp"
32using keyple::core::util::ApduUtil;
33using keyple::core::util::cpp::Arrays;
35const std::map<int, const std::shared_ptr<StatusProperties>>
36 CommandGetData::STATUS_TABLE = [] {
37 std::map<int, const std::shared_ptr<StatusProperties>> m(
38 Command::STATUS_TABLE);
42 std::make_shared<StatusProperties>(
43 "Incorrect Lc",
typeid(IllegalParameterException))},
45 std::make_shared<StatusProperties>(
46 "Data referenced by P1-P2 not available",
47 typeid(DataAccessException))}});
52CommandGetData::CommandGetData(
53 std::shared_ptr<DtoAdapters::CommandContextDto> context, GetDataTag tag)
54: Command(CommandRef::GET_DATA, getExpectedTotalLength(tag), context)
55, mTagInfo(LegacySamConstants::
TagInfo::valueOf(name(tag)))
58 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
59 context->getTargetSam()->getClassByte(),
60 getCommandRef().getInstructionByte(),
63 static_cast<uint8_t
>(std::min(mTagInfo.getLength(), 255)))));
67CommandGetData::getExpectedTotalLength(GetDataTag tag)
69 return LegacySamConstants::TagInfo::valueOf(name(tag)).getTotalLength();
73CommandGetData::finalizeRequest()
79CommandGetData::isControlSamRequiredToFinalizeRequest()
const
85CommandGetData::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
87 setResponseAndCheckStatus(apduResponse);
88 const std::vector<std::uint8_t> dataOut = apduResponse->getDataOut();
91 const std::vector<std::uint8_t> header = mTagInfo.getHeader();
93 for (
int i = 0; i < static_cast<int>(header.size()); i++) {
94 if (dataOut[i] != header[i]) {
95 throw DataAccessException(
96 "Inconsistent BER-TLV tag. Expected: "
97 + std::to_string(header[i])
98 +
"h, Actual: " + std::to_string(dataOut[i]) +
"h");
102 getContext()->getTargetSam()->setCaCertificate(
103 Arrays::copyOfRange(dataOut, header.size(), dataOut.size()));
106const std::map<int, const std::shared_ptr<StatusProperties>>&
107CommandGetData::getStatusTable()
const
LegacySamConstants::TagInfo TagInfo