14#include "keyple/card/calypso/crypto/legacysam/CommandSamDataCipher.hpp"
21#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/CommandRef.hpp"
23#include "keyple/card/calypso/crypto/legacysam/CounterOverflowException.hpp"
24#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
25#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
26#include "keyple/card/generic/ApduRequestAdapter.hpp"
27#include "keyple/core/util/ApduUtil.hpp"
28#include "keyple/core/util/cpp/System.hpp"
29#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
37using keyple::card::generic::ApduRequestAdapter;
38using keyple::core::util::ApduUtil;
39using keyple::core::util::cpp::System;
40using keyple::core::util::cpp::exception::IllegalArgumentException;
44const std::map<int, const std::shared_ptr<StatusProperties>>
45 CommandSamDataCipher::STATUS_TABLE = [] {
46 std::map<int, const std::shared_ptr<StatusProperties>> m(
47 Command::STATUS_TABLE);
51 std::make_shared<StatusProperties>(
52 "Incorrect Lc",
typeid(IllegalParameterException))},
54 std::make_shared<StatusProperties>(
55 "An event counter cannot be incremented",
56 typeid(CounterOverflowException))},
58 std::make_shared<StatusProperties>(
59 std::string(
"Preconditions not satisfied:\n")
60 +
"- The SAM is locked.\n"
61 +
"- Ciphering key: ciphering forbidden (CipherEnableBit "
64 typeid(AccessForbiddenException))},
66 std::make_shared<StatusProperties>(
67 "Incorrect P1 (!=%0xxxxx0) or P2",
68 typeid(IllegalParameterException))},
70 std::make_shared<StatusProperties>(
71 "Record not found: deciphering key not found",
72 typeid(DataAccessException))}});
77CommandSamDataCipher::CommandSamDataCipher(
78 std::shared_ptr<DtoAdapters::CommandContextDto> context,
81 const std::vector<uint8_t>& plainData)
82: Command(CommandRef::SAM_DATA_CIPHER, 48, context)
84 const uint8_t cla = context->getTargetSam()->getClassByte();
85 const uint8_t inst = getCommandRef().getInstructionByte();
91 case DataType::CAAD_RECORD:
92 p2 =
static_cast<uint8_t
>(0xE7 + recordNumber);
94 case DataType::CEILINGS_FILE_RECORD:
95 p2 =
static_cast<uint8_t
>(0xB1 + recordNumber);
97 case DataType::ONE_CEILING_VALUE:
100 case DataType::PARAMETERS_RECORD:
104 throw IllegalArgumentException(
105 "Unsupported DataType: "
106 + std::to_string(
static_cast<int>(dataType)));
110 std::make_shared<ApduRequestAdapter>(
111 ApduUtil::build(cla, inst, p1, p2, plainData)));
114const std::map<int, const std::shared_ptr<StatusProperties>>&
115CommandSamDataCipher::getStatusTable()
const
121CommandSamDataCipher::finalizeRequest()
127CommandSamDataCipher::isControlSamRequiredToFinalizeRequest()
const
133CommandSamDataCipher::parseResponse(
134 std::shared_ptr<ApduResponseApi> apduResponse)
136 setResponseAndCheckStatus(apduResponse);
138 System::arraycopy(apduResponse->getApdu(), 0, mCipheredData, 0, 48);
141const std::vector<uint8_t>&
142CommandSamDataCipher::getCipheredData()
const
144 return mCipheredData;
Command::StatusProperties StatusProperties