14#include "keyple/card/calypso/crypto/legacysam/CommandUnlock.hpp"
21#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
23#include "keyple/card/calypso/crypto/legacysam/SecurityDataException.hpp"
24#include "keyple/core/util/ApduUtil.hpp"
25#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
33using keyple::core::util::ApduUtil;
34using keyple::core::util::cpp::exception::IllegalArgumentException;
36const std::map<int, const std::shared_ptr<StatusProperties>>
37 CommandUnlock::STATUS_TABLE = [] {
38 std::map<int, const std::shared_ptr<StatusProperties>> m(
39 Command::STATUS_TABLE);
43 std::make_shared<StatusProperties>(
44 "Incorrect Le",
typeid(IllegalParameterException))},
46 std::make_shared<StatusProperties>(
47 "Preconditions not satisfied (SAM not locked?)",
48 typeid(AccessForbiddenException))},
50 std::make_shared<StatusProperties>(
51 "Incorrect UnlockData",
typeid(SecurityDataException))}});
56CommandUnlock::CommandUnlock(
57 LegacySam::ProductType productType,
const std::vector<uint8_t>& unlockData)
58: Command(CommandRef::UNLOCK, 0, nullptr)
61 = productType == LegacySam::ProductType::SAM_S1DX ? 0x94 : 0x80;
62 const uint8_t p1 = 0x00;
63 const uint8_t p2 = 0x00;
65 if (unlockData.size() != 8 && unlockData.size() != 16) {
66 throw IllegalArgumentException(
67 "Unlock data is an incorrect length. Expected 8 or 16 bytes, got "
68 + std::to_string(unlockData.size()));
72 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
73 cla, getCommandRef().getInstructionByte(), p1, p2, unlockData)));
77CommandUnlock::finalizeRequest()
83CommandUnlock::isControlSamRequiredToFinalizeRequest()
const
89CommandUnlock::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
91 setResponseAndCheckStatus(apduResponse);
94const std::map<int, const std::shared_ptr<StatusProperties>>&
95CommandUnlock::getStatusTable()
const