bool ISO7816StorageCardService::readData(boost::shared_ptr<Location> location, boost::shared_ptr<AccessInfo> /*aiToUse*/, void* data, size_t dataLength, CardBehavior /*behaviorFlags*/) { bool ret = false; EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null."); EXCEPTION_ASSERT_WITH_LOG(data, std::invalid_argument, "data cannot be null."); boost::shared_ptr<ISO7816Location> icLocation = boost::dynamic_pointer_cast<ISO7816Location>(location); EXCEPTION_ASSERT_WITH_LOG(icLocation, std::invalid_argument, "location must be a ISO7816Location."); if (icLocation->fileid != 0) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->fileid); } else { unsigned char defaultdf[16]; memset(defaultdf, 0x00, sizeof(defaultdf)); if (memcmp(icLocation->dfname, defaultdf, sizeof(defaultdf))) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->dfname, icLocation->dfnamelen); } } switch (icLocation->fileType) { case IFT_MASTER: case IFT_DIRECTORY: if (icLocation->dataObject > 0) { ret = getISO7816Chip()->getISO7816Commands()->getData(data, dataLength, icLocation->dataObject); } else { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Please specify a data object."); } break; case IFT_TRANSPARENT: ret = getISO7816Chip()->getISO7816Commands()->readBinay(data, dataLength, 0); break; case IFT_LINEAR_FIXED: case IFT_LINEAR_VARIABLE: case IFT_CYCLIC: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Not implemented yet."); break; default: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Doesn't know how to read on this file."); break; } return ret; }
void ISO7816StorageCardService::writeData(std::shared_ptr<Location> location, std::shared_ptr<AccessInfo> /*aiToUse*/, std::shared_ptr<AccessInfo> /*aiToWrite*/, const std::vector<unsigned char>& data, CardBehavior /*behaviorFlags*/) { EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null."); std::shared_ptr<ISO7816Location> icLocation = std::dynamic_pointer_cast<ISO7816Location>(location); EXCEPTION_ASSERT_WITH_LOG(icLocation, std::invalid_argument, "location must be a ISO7816Location."); if (icLocation->fileid != 0) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->fileid); } else { unsigned char defaultdf[16]; memset(defaultdf, 0x00, sizeof(defaultdf)); if (memcmp(icLocation->dfname, defaultdf, sizeof(defaultdf))) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->dfname, icLocation->dfnamelen); } } switch (icLocation->fileType) { case IFT_MASTER: case IFT_DIRECTORY: { if (icLocation->dataObject > 0) { getISO7816Chip()->getISO7816Commands()->putData(data, icLocation->dataObject); } else { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Please specify a data object."); } } break; case IFT_TRANSPARENT: { getISO7816Chip()->getISO7816Commands()->writeBinary(data, 0); } break; case IFT_LINEAR_FIXED: case IFT_LINEAR_VARIABLE: case IFT_CYCLIC: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Not implemented yet."); break; default: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Doesn't know how to write on this file."); break; } }
bool ISO7816StorageCardService::erase(boost::shared_ptr<Location> location, boost::shared_ptr<AccessInfo> /*aiToUse*/) { bool ret = false; EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null."); boost::shared_ptr<ISO7816Location> icLocation = boost::dynamic_pointer_cast<ISO7816Location>(location); EXCEPTION_ASSERT_WITH_LOG(icLocation, std::invalid_argument, "location must be a ISO7816Location."); if (icLocation->fileid != 0) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->fileid); } else { unsigned char defaultdf[16]; memset(defaultdf, 0x00, sizeof(defaultdf)); if (memcmp(icLocation->dfname, defaultdf, sizeof(defaultdf))) { getISO7816Chip()->getISO7816Commands()->selectFile(icLocation->dfname, icLocation->dfnamelen); } } switch (icLocation->fileType) { case IFT_TRANSPARENT: { getISO7816Chip()->getISO7816Commands()->eraseBinay(0); ret = true; } break; case IFT_LINEAR_FIXED: case IFT_LINEAR_VARIABLE: case IFT_CYCLIC: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Not implemented yet."); break; default: THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Doesn't know how to write on this file."); break; } return ret; }
boost::shared_ptr<TwicChip> getTwicChip() { return boost::dynamic_pointer_cast<TwicChip>(getISO7816Chip()); };