本文整理汇总了C++中THROW_EXCEPTION_WITH_LOG函数的典型用法代码示例。如果您正苦于以下问题:C++ THROW_EXCEPTION_WITH_LOG函数的具体用法?C++ THROW_EXCEPTION_WITH_LOG怎么用?C++ THROW_EXCEPTION_WITH_LOG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了THROW_EXCEPTION_WITH_LOG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: INFO_
void MifareSTidSTRCommands::loadKey(boost::shared_ptr<Location> location, boost::shared_ptr<Key> key, MifareKeyType keytype)
{
INFO_("Loading key... location {%s} key type {0x%x(%d)}", location->serialize().c_str(), keytype, keytype);
EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null.");
EXCEPTION_ASSERT_WITH_LOG(key, std::invalid_argument, "key cannot be null.");
boost::shared_ptr<MifareLocation> mLocation = boost::dynamic_pointer_cast<MifareLocation>(location);
boost::shared_ptr<MifareKey> mKey = boost::dynamic_pointer_cast<MifareKey>(key);
EXCEPTION_ASSERT_WITH_LOG(mLocation, std::invalid_argument, "location must be a MifareLocation.");
EXCEPTION_ASSERT_WITH_LOG(mKey, std::invalid_argument, "key must be a MifareKey.");
boost::shared_ptr<KeyStorage> key_storage = key->getKeyStorage();
if (boost::dynamic_pointer_cast<ComputerMemoryKeyStorage>(key_storage))
{
INFO_SIMPLE_("Using computer memory key storage !");
loadKey(static_cast<unsigned char>(mLocation->sector), keytype, key->getData(), key->getLength(), true);
}
else if (boost::dynamic_pointer_cast<ReaderMemoryKeyStorage>(key_storage))
{
INFO_SIMPLE_("Using reader memory key storage !");
// Don't load the key when reader memory, except if specified
if (!key->isEmpty())
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "It's not possible to change a key at specific index through host/reader connection. Please use SKB configuration card instead.");
}
}
else
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "The key storage type is not supported for this card/reader.");
}
}
示例2: THROW_EXCEPTION_WITH_LOG
void SAMAV1ISO7816Commands::changeKUCEntry(unsigned char kucno, std::shared_ptr<SAMKucEntry> kucentry, std::shared_ptr<DESFireKey> key)
{
if (d_crypto->d_sessionKey.size() == 0)
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Failed: AuthentificationHost have to be done before use such command.");
unsigned char data[6] = {};
memcpy(data, &kucentry->getKucEntryStruct(), 6);
std::vector<unsigned char> vectordata(data, data + 6);
std::vector<unsigned char> encdatalittle;
if (key->getKeyType() == DF_KEY_DES)
encdatalittle = d_crypto->sam_encrypt(d_crypto->d_sessionKey, vectordata);
else
encdatalittle = d_crypto->sam_crc_encrypt(d_crypto->d_sessionKey, vectordata, key);
unsigned char proMas = kucentry->getUpdateMask();
unsigned char cmd[] = { d_cla, 0xcc, kucno, proMas, 0x08 };
std::vector<unsigned char> cmd_vector(cmd, cmd + 5), result;
cmd_vector.insert(cmd_vector.end(), encdatalittle.begin(), encdatalittle.end());
result = transmit(cmd_vector);
if (result.size() >= 2 && (result[result.size() - 2] != 0x90 || result[result.size() - 1] != 0x00))
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "changeKUCEntry failed.");
}
示例3: switch
void OpenSSLSymmetricCipher::update(OpenSSLSymmetricCipherContext& context, const std::vector<unsigned char>& src)
{
int r = 0;
int outlen = 0;
unsigned char* buf = new unsigned char[src.size() + context.blockSize()];
switch (context.method())
{
case M_ENCRYPT:
{
r = EVP_EncryptUpdate(context.ctx(), buf, &outlen, &src[0], static_cast<int>(src.size()));
break;
}
case M_DECRYPT:
{
r = EVP_DecryptUpdate(context.ctx(), buf, &outlen, &src[0], static_cast<int>(src.size()));
break;
}
default:
{
THROW_EXCEPTION_WITH_LOG(std::runtime_error, "Unhandled method");
}
}
if (r != 1)
{
delete[] buf;
THROW_EXCEPTION_WITH_LOG(OpenSSLException, "");
}
context.data().insert(context.data().end(), buf, buf + outlen);
delete[] buf;
}
示例4: cmd_vector
void SAMAV1ISO7816Commands::authenticateHost_AES_3K3DES(std::shared_ptr<DESFireKey> key, unsigned char keyno)
{
std::vector<unsigned char> data;
unsigned char authMode = 0x00;
data.push_back(keyno);
data.push_back(key->getKeyVersion());
unsigned char cmdp1[] = { d_cla, 0xa4, authMode, 0x00, 0x02, 0x00 };
std::vector<unsigned char> cmd_vector(cmdp1, cmdp1 + 6), result;
cmd_vector.insert(cmd_vector.end() - 1, data.begin(), data.end());
result = transmit(cmd_vector);
if (result.size() >= 2 && (result[result.size() - 2] != 0x90 || result[result.size() - 1] != 0xaf))
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "authenticateHost_AES_3K3DES P1 failed.");
std::vector<unsigned char> encRndB(result.begin(), result.end() - 2);
std::vector<unsigned char> encRndAB = d_crypto->authenticateHostP1(key, encRndB, keyno);
unsigned char cmdp2[] = { d_cla, 0xa4, 0x00, 0x00, (unsigned char)(encRndAB.size()), 0x00 };
cmd_vector.assign(cmdp2, cmdp2 + 6);
cmd_vector.insert(cmd_vector.end() - 1, encRndAB.begin(), encRndAB.end());
result = transmit(cmd_vector);
if (result.size() >= 2 && (result[result.size() - 2] != 0x90 || result[result.size() - 1] != 0x00))
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "authenticateHost_AES_3K3DES P2 failed.");
std::vector<unsigned char> encRndA1(result.begin(), result.end() - 2);
d_crypto->authenticateHostP2(keyno, encRndA1, key);
}
示例5: getDESFireChip
bool DESFireStorageCardService::erase()
{
bool r = false;
boost::shared_ptr<DESFireCommands> cmd = getDESFireChip()->getDESFireCommands();
if (cmd->selectApplication(0))
{
if (cmd->authenticate(0))
{
if (cmd->erase())
{
r = cmd->changeKey(0, boost::shared_ptr<DESFireKey>(new DESFireKey(string("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"))));
}
}
else
{
THROW_EXCEPTION_WITH_LOG(CardException, EXCEPTION_MSG_AUTHENTICATE);
}
}
else
{
THROW_EXCEPTION_WITH_LOG(CardException, EXCEPTION_MSG_SELECTAPPLICATION);
}
return r;
}
示例6: EXCEPTION_ASSERT_WITH_LOG
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;
}
示例7: EXCEPTION_ASSERT_WITH_LOG
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;
}
}
示例8: getMifareChip
void MifareCommands::setSectorToMAD(long aid, unsigned int sector, std::shared_ptr<MifareKey> madKeyA, std::shared_ptr<MifareKey> madKeyB)
{
MifareAccessInfo::SectorAccessBits sab;
if (!madKeyA->isEmpty())
{
getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_A, madKeyA);
getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_A, madKeyA);
}
if (madKeyB->isEmpty())
{
sab.setTransportConfiguration();
}
else
{
getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_B, madKeyB);
getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_B, madKeyB);
sab.setAReadBWriteConfiguration();
}
if (sector < 16)
{
if (sector == 0)
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't make reference to the MAD itself.");
}
std::vector<unsigned char> madbuf = readSector(0, 1, sab);
if (!madbuf.size())
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD.");
}
madbuf[(sector * 2)] = aid & 0xff;
madbuf[sector * 2 + 1] = (aid & 0xff00) >> 8;
if (madbuf[1] == 0x00)
{
// BCD Nibble representation
madbuf[1] = static_cast<unsigned char>(sector % 10);
if (sector >= 10)
{
madbuf[1] |= 0x10;
}
}
madbuf[0] = calculateMADCrc(&madbuf[0], madbuf.size());
writeSector(0, 1, madbuf, sab);
}
else
{
if (sector == 16)
示例9: getMifareChip
unsigned int MifareCommands::getSectorFromMAD(long aid, boost::shared_ptr<MifareKey> madKeyA)
{
unsigned int sector = static_cast<unsigned int>(-1);
MifareAccessInfo::SectorAccessBits sab;
if (!madKeyA->isEmpty())
{
getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_A, madKeyA);
}
unsigned char madbuf[32];
memset(madbuf, 0x00, sizeof(madbuf));
if (!readSector(0, 1, madbuf, sizeof(madbuf), sab))
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD.");
}
unsigned char madcrc = calculateMADCrc(madbuf, sizeof(madbuf));
if (madcrc != madbuf[0])
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Bad MAD CRC.");
}
sector = findReferencedSector(aid, madbuf, sizeof(madbuf));
if ((sector == static_cast<unsigned int>(-1)) && getChip()->getCardType() == "Mifare4K")
{
unsigned char madbuf2[48];
memset(madbuf2, 0x00, sizeof(madbuf2));
if (readSector(16, 0, madbuf2, sizeof(madbuf2), sab) != sizeof(madbuf2))
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD2.");
}
unsigned char mad2crc = calculateMADCrc(madbuf2, sizeof(madbuf2));
if (mad2crc != madbuf2[0])
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Bad MAD2 CRC.");
}
sector = findReferencedSector(aid, madbuf2, sizeof(madbuf2));
if (sector != static_cast<unsigned int>(-1))
{
sector += 16;
}
}
return sector;
}
示例10: switch
bool logicalaccess::MifarePlusISO7816ResultChecker::checkByte(uint8_t t)
{
switch (t)
{
case 0x06:
THROW_EXCEPTION_WITH_LOG(CardException, "Access conditions not fulfilled.");
break;
case 0x07:
THROW_EXCEPTION_WITH_LOG(CardException, "Too many read or write commands in the session or in the transaction");
break;
case 0x08:
THROW_EXCEPTION_WITH_LOG(CardException, "Invalid MAC in command or response");
break;
case 0x09:
THROW_EXCEPTION_WITH_LOG(CardException, "Block number is not valid");
break;
case 0x0A:
THROW_EXCEPTION_WITH_LOG(CardException, "Block number is not valid / not existing");
break;
case 0x0B:
THROW_EXCEPTION_WITH_LOG(CardException, "The current command code is not available at the current card state");
break;
case 0x0C:
THROW_EXCEPTION_WITH_LOG(CardException, "Length error");
break;
case 0x0F:
THROW_EXCEPTION_WITH_LOG(CardException, "General Manipulation Error: Failure in the operation of the PICC");
break;
case 0x90:
return true;
}
return false;
}
示例11: THROW_EXCEPTION_WITH_LOG
void MifareProfile::setKeyUsage(int index, MifareKeyType keytype, bool used)
{
if (index > static_cast<int>(getNbSectors()))
{
THROW_EXCEPTION_WITH_LOG(std::invalid_argument, "Index is greater than max sector number.");
}
boost::shared_ptr<MifareKey> key;
if (used)
{
key.reset(new MifareKey());
}
switch (keytype)
{
case KT_KEY_A:
{
d_key[index * 2] = key;
}
case KT_KEY_B:
{
d_key[index * 2 + 1] = key;
}
}
}
示例12: LOG
std::vector<unsigned char> OK5553ReaderUnit::rats()
{
std::vector<unsigned char> answer;
// Sending two RATS is not supported without a new Select. Doesn't send another one if the first successed.
if (d_successedRATS.size() == 0)
{
LOG(LogLevel::INFOS) << "Sending a RATS";
answer = getDefaultOK5553ReaderCardAdapter()->sendAsciiCommand("t020FE020");
answer = asciiToHex(answer);
if (answer.size() > 1)
{
if (answer[0] == answer.size() - 1)
{
answer.erase(answer.begin());
}
else
answer.clear();
}
else
{
answer.clear();
THROW_EXCEPTION_WITH_LOG(std::invalid_argument, "No tag present in rfid field");
}
d_successedRATS = answer;
}
else
{
answer = d_successedRATS;
}
return answer;
}
示例13: getDataTransport
bool OSDPReaderUnit::connectToReader()
{
bool ret = getDataTransport()->connect();
if (ret)
{
m_commands->initCommands(getOSDPConfiguration()->getRS485Address());
//Test if can read
m_commands->poll();
//Start Secure Channel
std::shared_ptr<OSDPChannel> challenge = m_commands->challenge();
checkPDAuthentication(challenge);
std::shared_ptr<OSDPChannel> crypt = m_commands->sCrypt();
//Successful Authentication
crypt->isSCB = true;
std::shared_ptr<OSDPChannel> result = m_commands->getProfile();
if (result->getCommandsType() == OSDPCommandsType::XRD)
{
std::vector<unsigned char>& data = result->getData();
if (data.size() > 2 && data[0x03] != 0x01)
{
std::shared_ptr<OSDPChannel> result = m_commands->setProfile(0x01);
if (result->getCommandsType() != OSDPCommandsType::ACK)
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Impossible to set Profile 0x01");
}
}
}
return ret;
}
示例14: memset
void ValueDataField::revertBinaryData(const void* data, size_t dataLengthBytes, unsigned int* pos, unsigned int fieldlen, void* revertedData, size_t revertedDataLengthBytes) const
{
unsigned int readSizeBits = fieldlen;
size_t extractedSizeBytes = (readSizeBits + 7) / 8;
unsigned int revertedSizeBits = readSizeBits;
size_t revertedTemporarySizeBytes = (revertedSizeBits + 7) / 8;
unsigned char* extractData = new unsigned char[extractedSizeBytes];
unsigned char* revertedTemporaryData = new unsigned char[revertedTemporarySizeBytes];
memset(extractData, 0x00, extractedSizeBytes);
memset(revertedTemporaryData, 0x00, revertedTemporarySizeBytes);
unsigned int tmp = 0;
if ((tmp = BitHelper::extract(extractData, extractedSizeBytes, data, dataLengthBytes, static_cast<unsigned int>(dataLengthBytes * 8), *pos, readSizeBits)) > 0)
{
if ((tmp = d_dataRepresentation->revertBinary(extractData, extractedSizeBytes, tmp, revertedTemporaryData, revertedTemporarySizeBytes)) > 0)
{
#if defined(UNIX)
if (revertedDataLengthBytes < revertedTemporarySizeBytes)
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "The size of the dest buffer is too small for memcpy");
memcpy(revertedData, revertedTemporaryData, revertedTemporarySizeBytes);
#else
memcpy_s(revertedData, revertedDataLengthBytes, revertedTemporaryData, revertedTemporarySizeBytes);
#endif
}
}
delete[] extractData;
delete[] revertedTemporaryData;
(*pos) += readSizeBits;
}
示例15: EXCEPTION_ASSERT_WITH_LOG
void MifarePCSCCommands::loadKey(boost::shared_ptr<Location> location, boost::shared_ptr<Key> key, MifareKeyType keytype)
{
EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null.");
EXCEPTION_ASSERT_WITH_LOG(key, std::invalid_argument, "key cannot be null.");
boost::shared_ptr<MifareLocation> mLocation = boost::dynamic_pointer_cast<MifareLocation>(location);
boost::shared_ptr<MifareKey> mKey = boost::dynamic_pointer_cast<MifareKey>(key);
EXCEPTION_ASSERT_WITH_LOG(mLocation, std::invalid_argument, "location must be a MifareLocation.");
EXCEPTION_ASSERT_WITH_LOG(mKey, std::invalid_argument, "key must be a MifareKey.");
boost::shared_ptr<KeyStorage> key_storage = key->getKeyStorage();
if (boost::dynamic_pointer_cast<ComputerMemoryKeyStorage>(key_storage))
{
loadKey(0, keytype, key->getData(), key->getLength());
}
else if (boost::dynamic_pointer_cast<ReaderMemoryKeyStorage>(key_storage))
{
// Don't load the key when reader memory, except if specified
if (!key->isEmpty())
{
boost::shared_ptr<ReaderMemoryKeyStorage> rmKs = boost::dynamic_pointer_cast<ReaderMemoryKeyStorage>(key_storage);
loadKey(rmKs->getKeySlot(), keytype, key->getData(), key->getLength(), rmKs->getVolatile());
}
}
else
{
THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "The key storage type is not supported for this card/reader.");
}
}