18#include "ByteArrayUtil.h"
19#include "IllegalStateException.h"
27using namespace keyple::core::util;
28using namespace keyple::core::util::cpp;
29using namespace keyple::core::util::cpp::exception;
32 const std::shared_ptr<CardSelectionResponseApi> cardSelectionResponse)
35 mPowerOnData = cardSelectionResponse->getPowerOnData();
36 if (mPowerOnData.empty()) {
37 throw IllegalStateException(
"ATR should not be empty.");
40 mSerialNumber = std::vector<uint8_t>(4);
46 const std::string extractRegex =
"3B(.{6}|.{10})805A(.{20})829000";
47 std::unique_ptr<Pattern> pattern = Pattern::compile(extractRegex);
50 std::unique_ptr<Matcher> matcher = pattern->matcher(mPowerOnData);
51 if (matcher->find(0)) {
52 const std::vector<uint8_t> atrSubElements = ByteArrayUtil::fromHex(matcher->group(2));
53 mPlatform = atrSubElements[0];
54 mApplicationType = atrSubElements[1];
55 mApplicationSubType = atrSubElements[2];
58 switch (mApplicationSubType) {
60 mSamProductType = ProductType::SAM_C1;
65 mSamProductType = ProductType::SAM_S1DX;
68 mSamProductType = ProductType::SAM_S1E1;
71 mSamProductType = ProductType::UNKNOWN;
75 mSoftwareIssuer = atrSubElements[3];
76 mSoftwareVersion = atrSubElements[4];
77 mSoftwareRevision = atrSubElements[5];
78 System::arraycopy(atrSubElements, 6, mSerialNumber, 0, 4);
81 ss <<
"SAM " << mSamProductType
82 <<
"PLATFORM = " << mPlatform <<
", "
83 <<
"APPTYPE = " << mApplicationType <<
"h, "
84 <<
"APPSUBTYPE = " << mApplicationSubType <<
"h, "
85 <<
"SWISSUER = " << mSoftwareIssuer <<
"h, "
86 <<
"SWVERSION = " << mSoftwareVersion <<
"h, "
87 <<
"SWREVISION = " << mSoftwareRevision;
88 mLogger->trace(
"%\n", ss.str());
89 mLogger->trace(
"SAM SERIALNUMBER = %\n", ByteArrayUtil::toHex(mSerialNumber));
92 mSamProductType = ProductType::UNKNOWN;
95 mApplicationSubType = 0;
98 mSoftwareRevision = 0;
105 if (type == CalypsoSam::ProductType::SAM_S1DX ||
106 type == CalypsoSam::ProductType::CSAM_F) {
120 switch (mSamProductType) {
121 case CalypsoSam::ProductType::SAM_C1:
123 case CalypsoSam::ProductType::SAM_S1DX:
125 case CalypsoSam::ProductType::SAM_S1E1:
127 case CalypsoSam::ProductType::CSAM_F:
136 return std::vector<uint8_t>(0);
146 return mSamProductType;
151 std::stringstream ss;
159 return mSerialNumber;
169 return mApplicationType;
174 return mApplicationSubType;
179 return mSoftwareIssuer;
184 return mSoftwareVersion;
189 return mSoftwareRevision;
uint8_t getApplicationType() const final
uint8_t getClassByte() const
uint8_t getSoftwareVersion() const final
uint8_t getPlatform() const final
const std::string & getPowerOnData() const override
int getMaxDigestDataLength() const
CalypsoSamAdapter(const std::shared_ptr< CardSelectionResponseApi > cardSelectionResponse)
uint8_t getSoftwareIssuer() const final
const std::vector< uint8_t > getSelectApplicationResponse() const override
const std::string getProductInfo() const override
const std::vector< uint8_t > & getSerialNumber() const final
uint8_t getApplicationSubType() const final
uint8_t getSoftwareRevision() const final
CalypsoSam::ProductType getProductType() const final
CalypsoSam::ProductType ProductType