Enhance exception throwing with Boost Exception library
Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/security/additional-description.cpp b/src/security/additional-description.cpp
index 6aed34a..c912638 100644
--- a/src/security/additional-description.cpp
+++ b/src/security/additional-description.cpp
@@ -46,7 +46,7 @@
{
auto it = m_info.find(key);
if (it == m_info.end())
- throw Error("Entry does not exist for key (" + key + ")");
+ BOOST_THROW_EXCEPTION(Error("Entry does not exist for key (" + key + ")"));
return it->second;
}
@@ -136,14 +136,14 @@
AdditionalDescription::wireDecode(const Block& wire)
{
if (!wire.hasWire()) {
- throw Error("The supplied block does not contain wire format");
+ BOOST_THROW_EXCEPTION(Error("The supplied block does not contain wire format"));
}
m_wire = wire;
m_wire.parse();
if (m_wire.type() != tlv::AdditionalDescription)
- throw Error("Unexpected TLV type when decoding AdditionalDescription");
+ BOOST_THROW_EXCEPTION(Error("Unexpected TLV type when decoding AdditionalDescription"));
Block::element_const_iterator it = m_wire.elements_begin();
while (it != m_wire.elements_end()) {
@@ -151,14 +151,14 @@
entry.parse();
if (entry.type() != tlv::DescriptionEntry)
- throw Error("Unexpected TLV type when decoding DescriptionEntry");
+ BOOST_THROW_EXCEPTION(Error("Unexpected TLV type when decoding DescriptionEntry"));
if (entry.elements_size() != 2)
- throw Error("DescriptionEntry does not have two sub-TLVs");
+ BOOST_THROW_EXCEPTION(Error("DescriptionEntry does not have two sub-TLVs"));
if (entry.elements()[KEY_OFFSET].type() != tlv::DescriptionKey ||
entry.elements()[VALUE_OFFSET].type() != tlv::DescriptionValue)
- throw Error("Invalid DescriptionKey or DescriptionValue field");
+ BOOST_THROW_EXCEPTION(Error("Invalid DescriptionKey or DescriptionValue field"));
m_info[readString(entry.elements()[KEY_OFFSET])] = readString(entry.elements()[VALUE_OFFSET]);
it++;
diff --git a/src/security/certificate.cpp b/src/security/certificate.cpp
index e25a92e..837872a 100644
--- a/src/security/certificate.cpp
+++ b/src/security/certificate.cpp
@@ -261,7 +261,7 @@
idCert.MessageEnd();
}
catch (CryptoPP::BERDecodeErr&) {
- throw Error("Certificate Decoding Error");
+ BOOST_THROW_EXCEPTION(Error("Certificate Decoding Error"));
}
}
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 1364229..bb651bc 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -104,14 +104,14 @@
case tlv::SignatureSha256WithEcdsa:
{
if (!static_cast<bool>(m_keyLocatorChecker))
- throw Error("Strong signature requires KeyLocatorChecker");
+ BOOST_THROW_EXCEPTION(Error("Strong signature requires KeyLocatorChecker"));
return;
}
case tlv::DigestSha256:
return;
default:
- throw Error("Unsupported signature type");
+ BOOST_THROW_EXCEPTION(Error("Unsupported signature type"));
}
}
@@ -245,7 +245,7 @@
if (sigType != tlv::SignatureSha256WithRsa &&
sigType != tlv::SignatureSha256WithEcdsa)
{
- throw Error("FixedSigner is only meaningful for strong signature type");
+ BOOST_THROW_EXCEPTION(Error("FixedSigner is only meaningful for strong signature type"));
}
}
@@ -389,7 +389,7 @@
// Get checker.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.type>"));
std::string type = propertyIt->second.data();
@@ -400,7 +400,7 @@
else if (boost::iequals(type, "fixed-signer"))
return createFixedSignerChecker(configSection, configFilename);
else
- throw Error("Unsupported checker type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker type: " + type));
}
private:
@@ -413,21 +413,21 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
// Get checker.key-locator
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "key-locator"))
- throw Error("Expect <checker.key-locator>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator>"));
shared_ptr<KeyLocatorChecker> keyLocatorChecker =
KeyLocatorCheckerFactory::create(propertyIt->second, configFilename);
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return make_shared<CustomizedChecker>(getSigType(sigType), keyLocatorChecker);
}
@@ -441,13 +441,13 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return make_shared<HierarchicalChecker>(getSigType(sigType));
}
@@ -461,7 +461,7 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
@@ -470,14 +470,14 @@
for (; propertyIt != configSection.end(); propertyIt++)
{
if (!boost::iequals(propertyIt->first, "signer"))
- throw Error("Expect <checker.signer> but get <checker." +
- propertyIt->first + ">");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer> but get <checker." +
+ propertyIt->first + ">"));
signers.push_back(getSigner(propertyIt->second, configFilename));
}
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return shared_ptr<FixedSignerChecker>(new FixedSignerChecker(getSigType(sigType),
signers));
@@ -492,7 +492,7 @@
// Get checker.signer.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.signer.type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.type>"));
std::string type = propertyIt->second.data();
propertyIt++;
@@ -501,14 +501,14 @@
{
// Get checker.signer.file-name
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "file-name"))
- throw Error("Expect <checker.signer.file-name>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.file-name>"));
path certfilePath = absolute(propertyIt->second.data(),
path(configFilename).parent_path());
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.signer");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.signer"));
shared_ptr<IdentityCertificate> idCert
= io::load<IdentityCertificate>(certfilePath.c_str());
@@ -516,31 +516,31 @@
if (static_cast<bool>(idCert))
return idCert;
else
- throw Error("Cannot read certificate from file: " +
- certfilePath.native());
+ BOOST_THROW_EXCEPTION(Error("Cannot read certificate from file: " +
+ certfilePath.native()));
}
else if (boost::iequals(type, "base64"))
{
// Get checker.signer.base64-string
if (propertyIt == configSection.end() ||
!boost::iequals(propertyIt->first, "base64-string"))
- throw Error("Expect <checker.signer.base64-string>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.base64-string>"));
std::stringstream ss(propertyIt->second.data());
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.signer");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.signer"));
shared_ptr<IdentityCertificate> idCert = io::load<IdentityCertificate>(ss);
if (static_cast<bool>(idCert))
return idCert;
else
- throw Error("Cannot decode certificate from string");
+ BOOST_THROW_EXCEPTION(Error("Cannot decode certificate from string"));
}
else
- throw Error("Unsupported checker.signer type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.signer type: " + type));
}
static uint32_t
@@ -553,7 +553,7 @@
else if (boost::iequals(sigType, "sha256"))
return tlv::DigestSha256;
else
- throw Error("Unsupported signature type");
+ BOOST_THROW_EXCEPTION(Error("Unsupported signature type"));
}
};
diff --git a/src/security/conf/filter.hpp b/src/security/conf/filter.hpp
index 8d0601c..3dfddde 100644
--- a/src/security/conf/filter.hpp
+++ b/src/security/conf/filter.hpp
@@ -152,14 +152,14 @@
ConfigSection::const_iterator propertyIt = configSection.begin();
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <filter.type>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <filter.type>!"));
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createNameFilter(configSection);
else
- throw Error("Unsupported filter.type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported filter.type: " + type));
}
private:
static shared_ptr<Filter>
@@ -169,7 +169,7 @@
propertyIt++;
if (propertyIt == configSection.end())
- throw Error("Expect more properties for filter(name)");
+ BOOST_THROW_EXCEPTION(Error("Expect more properties for filter(name)"));
if (boost::iequals(propertyIt->first, "name"))
{
@@ -181,14 +181,14 @@
}
catch (Name::Error& e)
{
- throw Error("Wrong filter.name: " + propertyIt->second.data());
+ BOOST_THROW_EXCEPTION(Error("Wrong filter.name: " + propertyIt->second.data()));
}
propertyIt++;
// Get filter.relation
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation"))
- throw Error("Expect <filter.relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <filter.relation>!"));
std::string relationString = propertyIt->second.data();
propertyIt++;
@@ -201,11 +201,11 @@
else if (boost::iequals(relationString, "is-strict-prefix-of"))
relation = RelationNameFilter::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported relation: " + relationString);
+ BOOST_THROW_EXCEPTION(Error("Unsupported relation: " + relationString));
if (propertyIt != configSection.end())
- throw Error("Expect the end of filter!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of filter!"));
return make_shared<RelationNameFilter>(name, relation);
}
@@ -215,7 +215,7 @@
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of filter!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of filter!"));
try
{
@@ -223,11 +223,11 @@
}
catch (Regex::Error& e)
{
- throw Error("Wrong filter.regex: " + regexString);
+ BOOST_THROW_EXCEPTION(Error("Wrong filter.regex: " + regexString));
}
}
else
- throw Error("Wrong filter(name) properties");
+ BOOST_THROW_EXCEPTION(Error("Wrong filter(name) properties"));
}
};
diff --git a/src/security/conf/key-locator-checker.hpp b/src/security/conf/key-locator-checker.hpp
index 7d5bb9c..667dfeb 100644
--- a/src/security/conf/key-locator-checker.hpp
+++ b/src/security/conf/key-locator-checker.hpp
@@ -234,14 +234,14 @@
// Get checker.key-locator.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.key-locator.type>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.type>!"));
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createKeyLocatorNameChecker(configSection, filename);
else
- throw Error("Unsupported checker.key-locator.type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.type: " + type));
}
private:
@@ -253,7 +253,7 @@
propertyIt++;
if (propertyIt == configSection.end())
- throw Error("Expect more checker.key-locator properties");
+ BOOST_THROW_EXCEPTION(Error("Expect more checker.key-locator properties"));
if (boost::iequals(propertyIt->first, "name"))
{
@@ -264,13 +264,13 @@
}
catch (Name::Error& e)
{
- throw Error("Invalid checker.key-locator.name: " +
- propertyIt->second.data());
+ BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.name: " +
+ propertyIt->second.data()));
}
propertyIt++;
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation"))
- throw Error("Expect <checker.key-locator.relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.relation>!"));
std::string relationString = propertyIt->second.data();
propertyIt++;
@@ -283,10 +283,10 @@
else if (boost::iequals(relationString, "is-strict-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported relation: " + relationString);
+ BOOST_THROW_EXCEPTION(Error("Unsupported relation: " + relationString));
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.key-locator!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
return shared_ptr<RelationKeyLocatorNameChecker>
(new RelationKeyLocatorNameChecker(name, relation));
@@ -297,7 +297,7 @@
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.key-locator!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
try
{
@@ -306,7 +306,7 @@
}
catch (Regex::Error& e)
{
- throw Error("Invalid checker.key-locator.regex: " + regexString);
+ BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.regex: " + regexString));
}
}
else if (boost::iequals(propertyIt->first, "hyper-relation"))
@@ -317,41 +317,41 @@
// Get k-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-regex"))
- throw Error("Expect <checker.key-locator.hyper-relation.k-regex>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-regex>!"));
std::string kRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get k-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-expand"))
- throw Error("Expect <checker.key-locator.hyper-relation.k-expand>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-expand>!"));
std::string kExpand = hPropertyIt->second.data();
hPropertyIt++;
// Get h-relation
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "h-relation"))
- throw Error("Expect <checker.key-locator.hyper-relation.h-relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.h-relation>!"));
std::string hRelation = hPropertyIt->second.data();
hPropertyIt++;
// Get p-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-regex"))
- throw Error("Expect <checker.key-locator.hyper-relation.p-regex>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-regex>!"));
std::string pRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get p-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-expand"))
- throw Error("Expect <checker.key-locator.hyper-relation.p-expand>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-expand>!"));
std::string pExpand = hPropertyIt->second.data();
hPropertyIt++;
if (hPropertyIt != hSection.end())
- throw Error("Expect the end of checker.key-locator.hyper-relation!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator.hyper-relation!"));
KeyLocatorChecker::Relation relation;
if (boost::iequals(hRelation, "equal"))
@@ -361,7 +361,8 @@
else if (boost::iequals(hRelation, "is-strict-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported checker.key-locator.hyper-relation.h-relation: " + hRelation);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.hyper-relation.h-relation: "
+ + hRelation));
try
{
@@ -372,11 +373,11 @@
}
catch (Regex::Error& e)
{
- throw Error("Invalid regex for key-locator.hyper-relation");
+ BOOST_THROW_EXCEPTION(Error("Invalid regex for key-locator.hyper-relation"));
}
}
else
- throw Error("Unsupported checker.key-locator");
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator"));
}
};
diff --git a/src/security/digest-sha256.cpp b/src/security/digest-sha256.cpp
index 3af551a..6e37eb5 100644
--- a/src/security/digest-sha256.cpp
+++ b/src/security/digest-sha256.cpp
@@ -32,7 +32,7 @@
: Signature(signature)
{
if (getType() != tlv::DigestSha256)
- throw Error("Incorrect signature type");
+ BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
}
} // namespace ndn
diff --git a/src/security/identity-certificate.cpp b/src/security/identity-certificate.cpp
index a80684e..1eaceac 100644
--- a/src/security/identity-certificate.cpp
+++ b/src/security/identity-certificate.cpp
@@ -94,7 +94,7 @@
IdentityCertificate::setPublicKeyName()
{
if (!isCorrectName(getName()))
- throw Error("Wrong Identity Certificate Name!");
+ BOOST_THROW_EXCEPTION(Error("Wrong Identity Certificate Name"));
m_publicKeyName = certificateNameToPublicKeyName(getName());
}
@@ -120,7 +120,7 @@
}
if (!foundIdString)
- throw Error("Incorrect identity certificate name " + certificateName.toUri());
+ BOOST_THROW_EXCEPTION(Error("Incorrect identity certificate name " + certificateName.toUri()));
Name tmpName = certificateName.getSubName(0, idCertComponentIndex);
string keyString("KEY");
@@ -135,7 +135,7 @@
}
if (!foundKeyString)
- throw Error("Incorrect identity certificate name " + certificateName.toUri());
+ BOOST_THROW_EXCEPTION(Error("Incorrect identity certificate name " + certificateName.toUri()));
return tmpName
.getSubName(0, keyComponentIndex)
diff --git a/src/security/identity.cpp b/src/security/identity.cpp
index 128b7bc..1093b9f 100644
--- a/src/security/identity.cpp
+++ b/src/security/identity.cpp
@@ -46,7 +46,7 @@
if (needInit)
m_impl->addIdentity(m_name);
else if (!m_impl->hasIdentity(m_name))
- throw Pib::Error("Identity: " + m_name.toUri() + " does not exist");
+ BOOST_THROW_EXCEPTION(Pib::Error("Identity: " + m_name.toUri() + " does not exist"));
}
const Name&
@@ -157,7 +157,7 @@
Identity::validityCheck() const
{
if (m_impl == nullptr)
- throw std::domain_error("Invalid Identity instance");
+ BOOST_THROW_EXCEPTION(std::domain_error("Invalid Identity instance"));
}
} // namespace security
diff --git a/src/security/key-chain.cpp b/src/security/key-chain.cpp
index 2950a50..16bc879 100644
--- a/src/security/key-chain.cpp
+++ b/src/security/key-chain.cpp
@@ -177,7 +177,7 @@
auto pibFactory = getPibFactories().find(pibScheme);
if (pibFactory == getPibFactories().end()) {
- throw KeyChain::Error("PIB scheme '" + pibScheme + "' is not supported");
+ BOOST_THROW_EXCEPTION(KeyChain::Error("PIB scheme '" + pibScheme + "' is not supported"));
}
pibScheme = pibFactory->second.canonicalName;
@@ -214,7 +214,7 @@
}
auto tpmFactory = getTpmFactories().find(tpmScheme);
if (tpmFactory == getTpmFactories().end()) {
- throw KeyChain::Error("TPM scheme '" + tpmScheme + "' is not supported");
+ BOOST_THROW_EXCEPTION(KeyChain::Error("TPM scheme '" + tpmScheme + "' is not supported"));
}
tpmScheme = tpmFactory->second.canonicalName;
@@ -256,8 +256,8 @@
if (!allowReset &&
!m_pib->getTpmLocator().empty() && m_pib->getTpmLocator() != canonicalTpmLocator)
// Tpm mismatch, but we do not want to reset PIB
- throw MismatchError("TPM locator supplied does not match TPM locator in PIB: " +
- m_pib->getTpmLocator() + " != " + canonicalTpmLocator);
+ BOOST_THROW_EXCEPTION(MismatchError("TPM locator supplied does not match TPM locator in PIB: "
+ + m_pib->getTpmLocator() + " != " + canonicalTpmLocator));
}
catch (SecPublicInfo::Error&) {
// TPM locator is not set in PIB yet.
@@ -482,7 +482,7 @@
signingCertName = m_pib->getDefaultCertificateNameForKey(params.getSignerName());
}
catch (SecPublicInfo::Error&) {
- throw Error("signing certificate does not exist");
+ BOOST_THROW_EXCEPTION(Error("signing certificate does not exist"));
}
signingCert = m_pib->getCertificate(signingCertName);
@@ -493,7 +493,7 @@
{
signingCert = m_pib->getCertificate(params.getSignerName());
if (signingCert == nullptr)
- throw Error("signing certificate does not exist");
+ BOOST_THROW_EXCEPTION(Error("signing certificate does not exist"));
break;
}
@@ -503,7 +503,7 @@
return std::make_tuple(DIGEST_SHA256_IDENTITY, sigInfo);
}
default:
- throw Error("Unrecognized signer type");
+ BOOST_THROW_EXCEPTION(Error("Unrecognized signer type"));
}
sigInfo.setSignatureType(getSignatureType(signingCert->getPublicKeyInfo().getKeyType(),
@@ -540,7 +540,7 @@
shared_ptr<IdentityCertificate> certificate = m_pib->getCertificate(certificateName);
if (certificate == nullptr)
- throw SecPublicInfo::Error("certificate does not exist");
+ BOOST_THROW_EXCEPTION(SecPublicInfo::Error("certificate does not exist"));
Signature sig;
@@ -587,7 +587,7 @@
{
Name keyName = cert.getPublicKeyName();
if (!m_tpm->doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
- throw SecTpm::Error("Private key does not exist");
+ BOOST_THROW_EXCEPTION(SecTpm::Error("Private key does not exist"));
SignatureInfo sigInfo(cert.getSignature().getInfo());
sigInfo.setKeyLocator(KeyLocator(cert.getName().getPrefix(-1)));
@@ -601,7 +601,7 @@
KeyChain::exportIdentity(const Name& identity, const std::string& passwordStr)
{
if (!m_pib->doesIdentityExist(identity))
- throw SecPublicInfo::Error("Identity does not exist");
+ BOOST_THROW_EXCEPTION(SecPublicInfo::Error("Identity does not exist"));
Name keyName = m_pib->getDefaultKeyNameForIdentity(identity);
@@ -612,7 +612,7 @@
}
catch (SecTpm::Error& e)
{
- throw SecPublicInfo::Error("Fail to export PKCS5 of private key");
+ BOOST_THROW_EXCEPTION(SecPublicInfo::Error("Fail to export PKCS5 of private key"));
}
shared_ptr<IdentityCertificate> cert;
@@ -842,7 +842,7 @@
case KEY_TYPE_ECDSA:
return tlv::SignatureSha256WithEcdsa;
default:
- throw Error("Unsupported key types");
+ BOOST_THROW_EXCEPTION(Error("Unsupported key types"));
}
}
diff --git a/src/security/key-params.hpp b/src/security/key-params.hpp
index d4840a2..1c911f4 100644
--- a/src/security/key-params.hpp
+++ b/src/security/key-params.hpp
@@ -128,7 +128,7 @@
SimplePublicKeyParams(const KeyParams& params)
: KeyParams(params.getKeyType())
{
- throw KeyParams::Error("Incorrect key parameters (incompatible key type)");
+ BOOST_THROW_EXCEPTION(KeyParams::Error("Incorrect key parameters (incompatible key type)"));
}
uint32_t
@@ -202,7 +202,7 @@
explicit
SimpleSymmetricKeyParams(const KeyParams& params)
{
- throw KeyParams::Error("Incorrect key parameters (incompatible key type)");
+ BOOST_THROW_EXCEPTION(KeyParams::Error("Incorrect key parameters (incompatible key type)"));
}
uint32_t
diff --git a/src/security/key.cpp b/src/security/key.cpp
index dc430c7..48c8aa3 100644
--- a/src/security/key.cpp
+++ b/src/security/key.cpp
@@ -194,7 +194,7 @@
Key::validityCheck() const
{
if (m_impl == nullptr)
- throw std::domain_error("Invalid Key instance");
+ BOOST_THROW_EXCEPTION(std::domain_error("Invalid Key instance"));
}
} // namespace security
diff --git a/src/security/pib-memory.cpp b/src/security/pib-memory.cpp
index 397b0db..09300f1 100644
--- a/src/security/pib-memory.cpp
+++ b/src/security/pib-memory.cpp
@@ -33,7 +33,7 @@
void
PibMemory::setTpmLocator(const std::string& tpmLocator)
{
- throw Error("PibMemory does not need a locator");
+ BOOST_THROW_EXCEPTION(Error("PibMemory does not need a locator"));
}
std::string
@@ -92,7 +92,7 @@
if (m_hasDefaultIdentity)
return m_defaultIdentity;
- throw Pib::Error("No default identity");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default identity"));
}
bool
@@ -131,7 +131,7 @@
PibMemory::getKeyBits(const Name& identity, const name::Component& keyId) const
{
if (!hasKey(identity, keyId))
- throw Pib::Error("No key");
+ BOOST_THROW_EXCEPTION(Pib::Error("No key"));
auto it = m_keys.find(getKeyName(identity, keyId));
return it->second;
@@ -154,7 +154,7 @@
Name keyName = getKeyName(identity, keyId);
if (!hasKey(identity, keyId))
- throw Pib::Error("No key");
+ BOOST_THROW_EXCEPTION(Pib::Error("No key"));
m_defaultKey[identity] = keyName;
}
@@ -164,7 +164,7 @@
{
auto it = m_defaultKey.find(identity);
if (it == m_defaultKey.end())
- throw Pib::Error("No default key");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default key"));
return it->second.get(-1);
}
@@ -208,7 +208,7 @@
PibMemory::getCertificate(const Name& certName) const
{
if (!hasCertificate(certName))
- throw Pib::Error("No cert");
+ BOOST_THROW_EXCEPTION(Pib::Error("No cert"));
auto it = m_certs.find(certName);
return it->second;
@@ -231,7 +231,7 @@
PibMemory::setDefaultCertificateOfKey(const Name& identity, const name::Component& keyId, const Name& certName)
{
if (!hasCertificate(certName))
- throw Pib::Error("No cert");
+ BOOST_THROW_EXCEPTION(Pib::Error("No cert"));
Name keyName = getKeyName(identity, keyId);
m_defaultCert[keyName] = certName;
@@ -244,11 +244,11 @@
auto it = m_defaultCert.find(keyName);
if (it == m_defaultCert.end())
- throw Pib::Error("No default certificate");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default certificate"));
auto certIt = m_certs.find(it->second);
if (certIt == m_certs.end())
- throw Pib::Error("No default certificate");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default certificate"));
else
return certIt->second;
}
diff --git a/src/security/pib-sqlite3.cpp b/src/security/pib-sqlite3.cpp
index 3a95b5d..b20ee7c 100644
--- a/src/security/pib-sqlite3.cpp
+++ b/src/security/pib-sqlite3.cpp
@@ -217,7 +217,7 @@
boost::filesystem::path actualDir;
if (dir == "") {
if (getenv("HOME") == nullptr)
- throw PibImpl::Error("Environment variable HOME is not set");
+ BOOST_THROW_EXCEPTION(PibImpl::Error("Environment variable HOME is not set"));
actualDir = boost::filesystem::path(getenv("HOME")) / ".ndn";
boost::filesystem::create_directories(actualDir);
@@ -237,7 +237,7 @@
);
if (result != SQLITE_OK)
- throw PibImpl::Error("PIB DB cannot be opened/created: " + dir);
+ BOOST_THROW_EXCEPTION(PibImpl::Error("PIB DB cannot be opened/created: " + dir));
// enable foreign key
@@ -248,7 +248,7 @@
result = sqlite3_exec(m_database, INITIALIZATION.c_str(), nullptr, nullptr, &errorMessage);
if (result != SQLITE_OK && errorMessage != nullptr) {
sqlite3_free(errorMessage);
- throw PibImpl::Error("PIB DB cannot be initialized");
+ BOOST_THROW_EXCEPTION(PibImpl::Error("PIB DB cannot be initialized"));
}
}
@@ -282,7 +282,7 @@
if (res == SQLITE_ROW)
return statement.getString(0);
else
- throw Pib::Error("TPM info does not exist");
+ BOOST_THROW_EXCEPTION(Pib::Error("TPM info does not exist"));
}
bool
@@ -337,7 +337,7 @@
if (statement.step() == SQLITE_ROW)
return Name(statement.getBlock(0));
else
- throw Pib::Error("No default identity");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default identity"));
}
bool
@@ -395,7 +395,7 @@
if (statement.step() == SQLITE_ROW)
return PublicKey(statement.getBlob(0), statement.getSize(0));
else
- throw Pib::Error("Key does not exist");
+ BOOST_THROW_EXCEPTION(Pib::Error("Key does not exist"));
}
std::set<name::Component>
@@ -423,7 +423,7 @@
Name keyName = getKeyName(identity, keyId);
if (!hasKey(identity, keyId)) {
- throw Pib::Error("No such key");
+ BOOST_THROW_EXCEPTION(Pib::Error("No such key"));
}
Sqlite3Statement statement(m_database, "UPDATE keys SET is_default=1 WHERE key_name=?");
@@ -435,7 +435,7 @@
PibSqlite3::getDefaultKeyOfIdentity(const Name& identity) const
{
if (!hasIdentity(identity)) {
- throw Pib::Error("Identity does not exist");
+ BOOST_THROW_EXCEPTION(Pib::Error("Identity does not exist"));
}
Sqlite3Statement statement(m_database,
@@ -449,7 +449,7 @@
return keyName.get(-1);
}
else
- throw Pib::Error("No default key");
+ BOOST_THROW_EXCEPTION(Pib::Error("No default key"));
}
bool
@@ -500,7 +500,7 @@
if (statement.step() == SQLITE_ROW)
return IdentityCertificate(statement.getBlock(0));
else
- throw Pib::Error("Certificate does not exit");
+ BOOST_THROW_EXCEPTION(Pib::Error("Certificate does not exit"));
}
std::set<Name>
@@ -527,7 +527,7 @@
const Name& certName)
{
if (!hasCertificate(certName)) {
- throw Pib::Error("Certificate does not exist");
+ BOOST_THROW_EXCEPTION(Pib::Error("Certificate does not exist"));
}
Sqlite3Statement statement(m_database,
@@ -550,7 +550,7 @@
if (statement.step() == SQLITE_ROW)
return IdentityCertificate(statement.getBlock(0));
else
- throw Pib::Error("Certificate does not exit");
+ BOOST_THROW_EXCEPTION(Pib::Error("Certificate does not exit"));
}
} // namespace security
diff --git a/src/security/public-key.cpp b/src/security/public-key.cpp
index 07b8137..5e0a607 100644
--- a/src/security/public-key.cpp
+++ b/src/security/public-key.cpp
@@ -46,7 +46,7 @@
PublicKey::computeDigest() const
{
if (m_key.empty())
- throw Error("Public key is empty");
+ BOOST_THROW_EXCEPTION(Error("Public key is empty"));
if (m_digest.hasWire())
return m_digest;
@@ -110,8 +110,8 @@
else if (algorithm == oid::ECDSA)
m_type = KEY_TYPE_ECDSA;
else
- throw Error("Only RSA/ECDSA public keys are supported for now (" +
- algorithm.toString() + " requested)");
+ BOOST_THROW_EXCEPTION(Error("Only RSA/ECDSA public keys are supported for now (" +
+ algorithm.toString() + " requested)"));
}
}
@@ -120,7 +120,7 @@
catch (CryptoPP::BERDecodeErr& err)
{
m_type = KEY_TYPE_NULL;
- throw Error("PublicKey decoding error");
+ BOOST_THROW_EXCEPTION(Error("PublicKey decoding error"));
}
m_digest.reset();
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index 65e394c..462f215 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -130,7 +130,7 @@
#endif
);
if (res != SQLITE_OK)
- throw Error("identity DB cannot be opened/created");
+ BOOST_THROW_EXCEPTION(Error("identity DB cannot be opened/created"));
BOOST_ASSERT(m_database != nullptr);
@@ -228,7 +228,7 @@
}
else {
sqlite3_finalize(statement);
- throw SecPublicInfo::Error("TPM info does not exist");
+ BOOST_THROW_EXCEPTION(SecPublicInfo::Error("TPM info does not exist"));
}
}
@@ -321,7 +321,7 @@
SecPublicInfoSqlite3::doesPublicKeyExist(const Name& keyName)
{
if (keyName.empty())
- throw Error("Incorrect key name " + keyName.toUri());
+ BOOST_THROW_EXCEPTION(Error("Incorrect key name " + keyName.toUri()));
string keyId = keyName.get(-1).toUri();
Name identityName = keyName.getPrefix(-1);
@@ -387,7 +387,7 @@
SecPublicInfoSqlite3::getPublicKey(const Name& keyName)
{
if (keyName.empty())
- throw Error("SecPublicInfoSqlite3::getPublicKey Empty keyName");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getPublicKey Empty keyName"));
string keyId = keyName.get(-1).toUri();
Name identityName = keyName.getPrefix(-1);
@@ -411,7 +411,7 @@
}
else {
sqlite3_finalize(statement);
- throw Error("SecPublicInfoSqlite3::getPublicKey public key does not exist");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getPublicKey public key does not exist"));
}
}
@@ -545,7 +545,8 @@
}
catch (tlv::Error&) {
sqlite3_finalize(statement);
- throw Error("SecPublicInfoSqlite3::getCertificate certificate cannot be decoded");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getCertificate certificate cannot be "
+ "decoded"));
}
sqlite3_finalize(statement);
@@ -553,7 +554,8 @@
}
else {
sqlite3_finalize(statement);
- throw Error("SecPublicInfoSqlite3::getCertificate certificate does not exist");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getCertificate certificate does not "
+ "exist"));
}
}
@@ -575,7 +577,7 @@
}
else {
sqlite3_finalize(statement);
- throw Error("SecPublicInfoSqlite3::getDefaultIdentity no default identity");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getDefaultIdentity no default identity"));
}
}
@@ -629,7 +631,8 @@
}
else {
sqlite3_finalize(statement);
- throw Error("SecPublicInfoSqlite3::getDefaultKeyNameForIdentity key not found");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getDefaultKeyNameForIdentity key not "
+ "found"));
}
}
@@ -637,7 +640,7 @@
SecPublicInfoSqlite3::setDefaultKeyNameForIdentityInternal(const Name& keyName)
{
if (!doesPublicKeyExist(keyName))
- throw Error("Key does not exist:" + keyName.toUri());
+ BOOST_THROW_EXCEPTION(Error("Key does not exist:" + keyName.toUri()));
string keyId = keyName.get(-1).toUri();
Name identityName = keyName.getPrefix(-1);
@@ -673,7 +676,7 @@
SecPublicInfoSqlite3::getDefaultCertificateNameForKey(const Name& keyName)
{
if (keyName.empty())
- throw Error("SecPublicInfoSqlite3::getDefaultCertificateNameForKey wrong key");
+ BOOST_THROW_EXCEPTION(Error("SecPublicInfoSqlite3::getDefaultCertificateNameForKey wrong key"));
string keyId = keyName.get(-1).toUri();
Name identityName = keyName.getPrefix(-1);
@@ -697,7 +700,7 @@
}
else {
sqlite3_finalize(statement);
- throw Error("certificate not found");
+ BOOST_THROW_EXCEPTION(Error("certificate not found"));
}
}
@@ -705,7 +708,7 @@
SecPublicInfoSqlite3::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
{
if (!doesCertificateExist(certificateName))
- throw Error("certificate does not exist:" + certificateName.toUri());
+ BOOST_THROW_EXCEPTION(Error("certificate does not exist:" + certificateName.toUri()));
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificateName);
string keyId = keyName.get(-1).toUri();
diff --git a/src/security/sec-public-info.cpp b/src/security/sec-public-info.cpp
index 6d9cc4c..2226f51 100644
--- a/src/security/sec-public-info.cpp
+++ b/src/security/sec-public-info.cpp
@@ -78,7 +78,7 @@
refreshDefaultCertificate();
if (m_defaultCertificate == nullptr)
- throw Error("No default certificate is set");
+ BOOST_THROW_EXCEPTION(Error("No default certificate is set"));
return m_defaultCertificate->getName();
}
@@ -98,7 +98,7 @@
Name keyName = Name(identityName).append(oss.str());
if (doesPublicKeyExist(keyName))
- throw Error("Key name already exists: " + keyName.toUri());
+ BOOST_THROW_EXCEPTION(Error("Key name already exists: " + keyName.toUri()));
return keyName;
}
diff --git a/src/security/sec-rule-relative.cpp b/src/security/sec-rule-relative.cpp
index 042d04f..4bf5eb9 100644
--- a/src/security/sec-rule-relative.cpp
+++ b/src/security/sec-rule-relative.cpp
@@ -46,7 +46,7 @@
m_signerNameRegex(signerRegex, signerExpand)
{
if (op != ">" && op != ">=" && op != "==")
- throw Error("op is wrong!");
+ BOOST_THROW_EXCEPTION(Error("op is wrong"));
}
SecRuleRelative::~SecRuleRelative()
diff --git a/src/security/sec-tpm-file.cpp b/src/security/sec-tpm-file.cpp
index 4551ce5..e20fa94 100644
--- a/src/security/sec-tpm-file.cpp
+++ b/src/security/sec-tpm-file.cpp
@@ -113,9 +113,9 @@
string keyURI = keyName.toUri();
if (doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
- throw Error("public key exists");
+ BOOST_THROW_EXCEPTION(Error("public key exists"));
if (doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
- throw Error("private key exists");
+ BOOST_THROW_EXCEPTION(Error("private key exists"));
string keyFileName = m_impl->maintainMapping(keyURI);
@@ -194,16 +194,16 @@
return;
}
default:
- throw Error("Unsupported key type!");
+ BOOST_THROW_EXCEPTION(Error("Unsupported key type"));
}
}
catch (KeyParams::Error& e)
{
- throw Error(e.what());
+ BOOST_THROW_EXCEPTION(Error(e.what()));
}
catch (CryptoPP::Exception& e)
{
- throw Error(e.what());
+ BOOST_THROW_EXCEPTION(Error(e.what()));
}
}
@@ -226,7 +226,7 @@
string keyURI = keyName.toUri();
if (!doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
- throw Error("Public Key does not exist");
+ BOOST_THROW_EXCEPTION(Error("Public Key does not exist"));
ostringstream os;
try
@@ -238,7 +238,7 @@
}
catch (CryptoPP::Exception& e)
{
- throw Error(e.what());
+ BOOST_THROW_EXCEPTION(Error(e.what()));
}
return make_shared<PublicKey>(reinterpret_cast<const uint8_t*>(os.str().c_str()),
@@ -308,7 +308,7 @@
string keyURI = keyName.toUri();
if (!doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
- throw Error("private key doesn't exists");
+ BOOST_THROW_EXCEPTION(Error("private key doesn't exist"));
try
{
@@ -347,7 +347,7 @@
return Block(tlv::SignatureValue, os.buf());
}
default:
- throw Error("Unsupported digest algorithm!");
+ BOOST_THROW_EXCEPTION(Error("Unsupported digest algorithm"));
}
}
case KEY_TYPE_ECDSA:
@@ -383,16 +383,16 @@
return Block(tlv::SignatureValue, sigBuffer);
}
default:
- throw Error("Unsupported digest algorithm!");
+ BOOST_THROW_EXCEPTION(Error("Unsupported digest algorithm"));
}
}
default:
- throw Error("Unsupported key type!");
+ BOOST_THROW_EXCEPTION(Error("Unsupported key type"));
}
}
catch (CryptoPP::Exception& e)
{
- throw Error(e.what());
+ BOOST_THROW_EXCEPTION(Error(e.what()));
}
}
@@ -401,7 +401,7 @@
SecTpmFile::decryptInTpm(const uint8_t* data, size_t dataLength,
const Name& keyName, bool isSymmetric)
{
- throw Error("SecTpmFile::decryptInTpm is not supported!");
+ BOOST_THROW_EXCEPTION(Error("SecTpmFile::decryptInTpm is not supported"));
// string keyURI = keyName.toUri();
// if (!isSymmetric)
// {
@@ -463,7 +463,7 @@
SecTpmFile::encryptInTpm(const uint8_t* data, size_t dataLength,
const Name& keyName, bool isSymmetric)
{
- throw Error("SecTpmFile::encryptInTpm is not supported!");
+ BOOST_THROW_EXCEPTION(Error("SecTpmFile::encryptInTpm is not supported"));
// string keyURI = keyName.toUri();
// if (!isSymmetric)
@@ -521,11 +521,10 @@
// }
}
-
void
SecTpmFile::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
{
- throw Error("SecTpmFile::generateSymmetricKeyInTpm is not supported!");
+ BOOST_THROW_EXCEPTION(Error("SecTpmFile::generateSymmetricKeyInTpm is not supported"));
// string keyURI = keyName.toUri();
// if (doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
diff --git a/src/security/sec-tpm-osx.cpp b/src/security/sec-tpm-osx.cpp
index 4400343..33a2c7f 100644
--- a/src/security/sec-tpm-osx.cpp
+++ b/src/security/sec-tpm-osx.cpp
@@ -250,7 +250,7 @@
OSStatus res = SecKeychainCopyDefault(&m_impl->m_keyChainRef);
if (res == errSecNoDefaultKeychain) //If no default key chain, create one.
- throw Error("No default keychain, create one first!");
+ BOOST_THROW_EXCEPTION(Error("No default keychain, please create one first"));
}
SecTpmOsx::~SecTpmOsx()
@@ -377,7 +377,7 @@
if (doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
{
- throw Error("keyName has existed");
+ BOOST_THROW_EXCEPTION(Error("keyName already exists"));
}
string keyNameUri = m_impl->toInternalKeyName(keyName, KEY_CLASS_PUBLIC);
@@ -410,7 +410,7 @@
break;
}
default:
- throw Error("Fail to create a key pair: Unsupported key type");
+ BOOST_THROW_EXCEPTION(Error("Fail to create a key pair: Unsupported key type"));
}
CFReleaser<CFNumberRef> cfKeySize = CFNumberCreate(0, kCFNumberIntType, &keySize);
@@ -434,11 +434,11 @@
if (unlockTpm(0, 0, false))
generateKeyPairInTpmInternal(keyName, params, true);
else
- throw Error("Fail to unlock the keychain");
+ BOOST_THROW_EXCEPTION(Error("Fail to unlock the keychain"));
}
else
{
- throw Error("Fail to create a key pair");
+ BOOST_THROW_EXCEPTION(Error("Fail to create a key pair"));
}
}
@@ -473,7 +473,7 @@
void
SecTpmOsx::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
{
- throw Error("SecTpmOsx::generateSymmetricKeyInTpm is not supported");
+ BOOST_THROW_EXCEPTION(Error("SecTpmOsx::generateSymmetricKeyInTpm is not supported"));
// if (doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
// throw Error("keyName has existed!");
@@ -511,7 +511,8 @@
CFReleaser<SecKeychainItemRef> publicKey = m_impl->getKey(keyName, KEY_CLASS_PUBLIC);
if (publicKey.get() == 0)
{
- throw Error("Requested public key [" + keyName.toUri() + "] does not exist in OSX Keychain");
+ BOOST_THROW_EXCEPTION(Error("Requested public key [" + keyName.toUri() + "] does not exist "
+ "in OSX Keychain"));
}
CFReleaser<CFDataRef> exportedKey;
@@ -522,7 +523,7 @@
&exportedKey.get());
if (res != errSecSuccess)
{
- throw Error("Cannot export requested public key from OSX Keychain");
+ BOOST_THROW_EXCEPTION(Error("Cannot export requested public key from OSX Keychain"));
}
shared_ptr<PublicKey> key = make_shared<PublicKey>(CFDataGetBytePtr(exportedKey.get()),
@@ -545,7 +546,8 @@
if (privateKey.get() == 0)
{
/// @todo Can this happen because of keychain is locked?
- throw Error("Private key [" + keyName.toUri() + "] does not exist in OSX Keychain");
+ BOOST_THROW_EXCEPTION(Error("Private key [" + keyName.toUri() + "] does not exist "
+ "in OSX Keychain"));
}
shared_ptr<PublicKey> publicKey = getPublicKeyFromTpm(keyName);
@@ -597,8 +599,8 @@
break;
}
default:
- throw Error("Unsupported key type" +
- boost::lexical_cast<std::string>(publicKey->getKeyType()));
+ BOOST_THROW_EXCEPTION(Error("Unsupported key type" +
+ boost::lexical_cast<std::string>(publicKey->getKeyType())));
}
OBufferStream pkcs8Os;
@@ -813,7 +815,8 @@
CFReleaser<SecKeychainItemRef> privateKey = m_impl->getKey(keyName, KEY_CLASS_PRIVATE);
if (privateKey.get() == 0)
{
- throw Error("Private key [" + keyName.toUri() + "] does not exist in OSX Keychain");
+ BOOST_THROW_EXCEPTION(Error("Private key [" + keyName.toUri() + "] does not exist "
+ "in OSX Keychain"));
}
CFReleaser<CFErrorRef> error;
@@ -821,7 +824,7 @@
CFReleaser<SecTransformRef> signer = SecSignTransformCreate((SecKeyRef)privateKey.get(),
&error.get());
if (error.get() != 0)
- throw Error("Fail to create signer");
+ BOOST_THROW_EXCEPTION(Error("Fail to create signer"));
// Set input
SecTransformSetAttribute(signer.get(),
@@ -829,7 +832,7 @@
dataRef.get(),
&error.get());
if (error.get() != 0)
- throw Error("Fail to configure input of signer");
+ BOOST_THROW_EXCEPTION(Error("Fail to configure input of signer"));
// Enable use of padding
SecTransformSetAttribute(signer.get(),
@@ -837,7 +840,7 @@
kSecPaddingPKCS1Key,
&error.get());
if (error.get() != 0)
- throw Error("Fail to configure digest algorithm of signer");
+ BOOST_THROW_EXCEPTION(Error("Fail to configure digest algorithm of signer"));
// Set padding type
SecTransformSetAttribute(signer.get(),
@@ -845,7 +848,7 @@
m_impl->getDigestAlgorithm(digestAlgorithm),
&error.get());
if (error.get() != 0)
- throw Error("Fail to configure digest algorithm of signer");
+ BOOST_THROW_EXCEPTION(Error("Fail to configure digest algorithm of signer"));
// Set padding attribute
long digestSize = m_impl->getDigestSize(digestAlgorithm);
@@ -855,7 +858,7 @@
cfDigestSize.get(),
&error.get());
if (error.get() != 0)
- throw Error("Fail to configure digest size of signer");
+ BOOST_THROW_EXCEPTION(Error("Fail to configure digest size of signer"));
// Actually sign
// C-style cast is used as per Apple convention
@@ -867,17 +870,17 @@
if (unlockTpm(0, 0, false))
return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, true);
else
- throw Error("Fail to unlock the keychain");
+ BOOST_THROW_EXCEPTION(Error("Fail to unlock the keychain"));
}
else
{
CFShow(error.get());
- throw Error("Fail to sign data");
+ BOOST_THROW_EXCEPTION(Error("Fail to sign data"));
}
}
if (signature.get() == 0)
- throw Error("Signature is NULL!\n");
+ BOOST_THROW_EXCEPTION(Error("Signature is NULL!\n"));
return Block(tlv::SignatureValue,
make_shared<Buffer>(CFDataGetBytePtr(signature.get()),
@@ -887,7 +890,7 @@
ConstBufferPtr
SecTpmOsx::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool sym)
{
- throw Error("SecTpmOsx::decryptInTpm is not supported");
+ BOOST_THROW_EXCEPTION(Error("SecTpmOsx::decryptInTpm is not supported"));
// KeyClass keyClass;
// if (sym)
@@ -936,7 +939,8 @@
CFReleaser<SecKeychainItemRef> privateKey = m_impl->getKey(keyName, keyClass);
if (privateKey.get() == 0)
{
- throw Error("Private key [" + keyName.toUri() + "] does not exist in OSX Keychain");
+ BOOST_THROW_EXCEPTION(Error("Private key [" + keyName.toUri() + "] does not exist "
+ "in OSX Keychain"));
}
CFReleaser<SecAccessRef> accRef;
@@ -978,7 +982,7 @@
ConstBufferPtr
SecTpmOsx::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool sym)
{
- throw Error("SecTpmOsx::encryptInTpm is not supported");
+ BOOST_THROW_EXCEPTION(Error("SecTpmOsx::encryptInTpm is not supported"));
// KeyClass keyClass;
// if (sym)
diff --git a/src/security/sec-tpm.cpp b/src/security/sec-tpm.cpp
index 5c12049..c84b2de 100644
--- a/src/security/sec-tpm.cpp
+++ b/src/security/sec-tpm.cpp
@@ -57,7 +57,7 @@
// derive key
if (!generateRandomBlock(salt, 8) || !generateRandomBlock(iv, 8))
- throw Error("Cannot generate salt or iv");
+ BOOST_THROW_EXCEPTION(Error("Cannot generate salt or iv"));
uint32_t iterationCount = 2048;
@@ -74,7 +74,7 @@
}
catch (CryptoPP::Exception& e)
{
- throw Error("Cannot derived the encryption key");
+ BOOST_THROW_EXCEPTION(Error("Cannot derived the encryption key"));
}
//encrypt
@@ -84,7 +84,7 @@
ConstBufferPtr pkcs8PrivateKey = exportPrivateKeyPkcs8FromTpm(keyName);
if (!static_cast<bool>(pkcs8PrivateKey))
- throw Error("Cannot export the private key, #1");
+ BOOST_THROW_EXCEPTION(Error("Cannot export the private key, #1"));
OBufferStream encryptedOs;
try
@@ -94,7 +94,7 @@
}
catch (CryptoPP::Exception& e)
{
- throw Error("Cannot export the private key, #2");
+ BOOST_THROW_EXCEPTION(Error("Cannot export the private key, #2"));
}
//encode
@@ -166,7 +166,7 @@
}
catch (CryptoPP::Exception& e)
{
- throw Error("Cannot export the private key, #3");
+ BOOST_THROW_EXCEPTION(Error("Cannot export the private key, #3"));
}
}
diff --git a/src/security/signature-sha256-with-ecdsa.cpp b/src/security/signature-sha256-with-ecdsa.cpp
index 642912b..7de71a2 100644
--- a/src/security/signature-sha256-with-ecdsa.cpp
+++ b/src/security/signature-sha256-with-ecdsa.cpp
@@ -32,17 +32,17 @@
: Signature(signature)
{
if (getType() != tlv::SignatureSha256WithEcdsa)
- throw Error("Incorrect signature type");
+ BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
if (!hasKeyLocator()) {
- throw Error("KeyLocator is missing");
+ BOOST_THROW_EXCEPTION(Error("KeyLocator is missing"));
}
}
void
SignatureSha256WithEcdsa::unsetKeyLocator()
{
- throw Error("KeyLocator cannot be reset for SignatureSha256WithEcdsa");
+ BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be reset for SignatureSha256WithEcdsa"));
}
} // namespace ndn
diff --git a/src/security/signature-sha256-with-rsa.cpp b/src/security/signature-sha256-with-rsa.cpp
index cda06e6..572257d 100644
--- a/src/security/signature-sha256-with-rsa.cpp
+++ b/src/security/signature-sha256-with-rsa.cpp
@@ -32,17 +32,17 @@
: Signature(signature)
{
if (getType() != tlv::SignatureSha256WithRsa)
- throw Error("Incorrect signature type");
+ BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
if (!hasKeyLocator()) {
- throw Error("KeyLocator is missing");
+ BOOST_THROW_EXCEPTION(Error("KeyLocator is missing"));
}
}
void
SignatureSha256WithRsa::unsetKeyLocator()
{
- throw Error("KeyLocator cannot be reset for SignatureSha256WithRsa");
+ BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be reset for SignatureSha256WithRsa"));
}
} // namespace ndn
diff --git a/src/security/validator-config.cpp b/src/security/validator-config.cpp
index 149c5dc..c9dbf4d 100644
--- a/src/security/validator-config.cpp
+++ b/src/security/validator-config.cpp
@@ -82,7 +82,7 @@
{
std::string msg = "Failed to read configuration file: ";
msg += filename;
- throw security::conf::Error(msg);
+ BOOST_THROW_EXCEPTION(security::conf::Error(msg));
}
load(inputFile, filename);
inputFile.close();
@@ -110,7 +110,7 @@
msg << "Failed to parse configuration file";
msg << " " << filename;
msg << " " << error.message() << " line " << error.line();
- throw security::conf::Error(msg.str());
+ BOOST_THROW_EXCEPTION(security::conf::Error(msg.str()));
}
load(tree, filename);
@@ -130,7 +130,7 @@
msg += ": ";
msg += filename;
msg += " no data";
- throw security::conf::Error(msg);
+ BOOST_THROW_EXCEPTION(security::conf::Error(msg));
}
for (security::conf::ConfigSection::const_iterator i = configSection.begin();
@@ -153,7 +153,7 @@
msg += " ";
msg += filename;
msg += " unrecognized section: " + sectionName;
- throw security::conf::Error(msg);
+ BOOST_THROW_EXCEPTION(security::conf::Error(msg));
}
}
}
@@ -168,14 +168,14 @@
// Get rule.id
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "id"))
- throw Error("Expect <rule.id>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <rule.id>!"));
std::string ruleId = propertyIt->second.data();
propertyIt++;
// Get rule.for
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,"for"))
- throw Error("Expect <rule.for> in rule: " + ruleId + "!");
+ BOOST_THROW_EXCEPTION(Error("Expect <rule.for> in rule: " + ruleId + "!"));
std::string usage = propertyIt->second.data();
propertyIt++;
@@ -186,8 +186,8 @@
else if (boost::iequals(usage, "interest"))
isForData = false;
else
- throw Error("Unrecognized <rule.for>: " + usage
- + " in rule: " + ruleId);
+ BOOST_THROW_EXCEPTION(Error("Unrecognized <rule.for>: " + usage
+ + " in rule: " + ruleId));
// Get rule.filter(s)
std::vector<shared_ptr<Filter> > filters;
@@ -197,7 +197,7 @@
{
if (boost::iequals(propertyIt->first, "checker"))
break;
- throw Error("Expect <rule.filter> in rule: " + ruleId);
+ BOOST_THROW_EXCEPTION(Error("Expect <rule.filter> in rule: " + ruleId));
}
filters.push_back(FilterFactory::create(propertyIt->second));
@@ -209,7 +209,7 @@
for (; propertyIt != configSection.end(); propertyIt++)
{
if (!boost::iequals(propertyIt->first, "checker"))
- throw Error("Expect <rule.checker> in rule: " + ruleId);
+ BOOST_THROW_EXCEPTION(Error("Expect <rule.checker> in rule: " + ruleId));
checkers.push_back(CheckerFactory::create(propertyIt->second, filename));
continue;
@@ -217,10 +217,10 @@
// Check other stuff
if (propertyIt != configSection.end())
- throw Error("Expect the end of rule: " + ruleId);
+ BOOST_THROW_EXCEPTION(Error("Expect the end of rule: " + ruleId));
if (checkers.size() == 0)
- throw Error("No <rule.checker> is specified in rule: " + ruleId);
+ BOOST_THROW_EXCEPTION(Error("No <rule.checker> is specified in rule: " + ruleId));
if (isForData)
{
@@ -255,7 +255,7 @@
// Get trust-anchor.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <trust-anchor.type>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.type>!"));
std::string type = propertyIt->second.data();
propertyIt++;
@@ -264,14 +264,14 @@
{
// Get trust-anchor.file
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,"file-name"))
- throw Error("Expect <trust-anchor.file-name>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.file-name>!"));
std::string file = propertyIt->second.data();
propertyIt++;
// Check other stuff
if (propertyIt != configSection.end())
- throw Error("Expect the end of trust-anchor!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of trust-anchor!"));
path certfilePath = absolute(file, path(filename).parent_path());
shared_ptr<IdentityCertificate> idCert =
@@ -284,8 +284,8 @@
m_anchors[idCert->getName().getPrefix(-1)] = idCert;
}
else
- throw Error("Cannot read certificate from file: " +
- certfilePath.native());
+ BOOST_THROW_EXCEPTION(Error("Cannot read certificate from file: " +
+ certfilePath.native()));
return;
}
@@ -293,14 +293,14 @@
{
// Get trust-anchor.base64-string
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "base64-string"))
- throw Error("Expect <trust-anchor.base64-string>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.base64-string>!"));
std::stringstream ss(propertyIt->second.data());
propertyIt++;
// Check other stuff
if (propertyIt != configSection.end())
- throw Error("Expect the end of trust-anchor!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of trust-anchor!"));
shared_ptr<IdentityCertificate> idCert = io::load<IdentityCertificate>(ss);
@@ -311,14 +311,14 @@
m_anchors[idCert->getName().getPrefix(-1)] = idCert;
}
else
- throw Error("Cannot decode certificate from base64-string");
+ BOOST_THROW_EXCEPTION(Error("Cannot decode certificate from base64-string"));
return;
}
else if (boost::iequals(type, "dir"))
{
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "dir"))
- throw Error("Expect <trust-anchor.dir>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.dir>"));
std::string dirString(propertyIt->second.data());
propertyIt++;
@@ -333,7 +333,7 @@
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of trust-anchor!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of trust-anchor"));
path dirPath = absolute(dirString, path(filename).parent_path());
@@ -344,7 +344,7 @@
return;
}
else
- throw Error("Expect <trust-anchor.refresh>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.refresh>!"));
}
else
{
@@ -371,7 +371,7 @@
m_shouldValidate = false;
}
else
- throw Error("Unsupported trust-anchor.type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported trust-anchor.type: " + type));
}
void
@@ -414,7 +414,7 @@
}
catch (boost::bad_lexical_cast&)
{
- throw Error("Bad number: " + refreshString);
+ BOOST_THROW_EXCEPTION(Error("Bad number: " + refreshString));
}
if (number == 0)
@@ -429,7 +429,7 @@
case 's':
return time::duration_cast<time::nanoseconds>(time::seconds(number));
default:
- throw Error(std::string("Wrong time unit: ") + unit);
+ BOOST_THROW_EXCEPTION(Error(std::string("Wrong time unit: ") + unit));
}
}
diff --git a/src/security/validity-period.cpp b/src/security/validity-period.cpp
index 008cd3c..c6f6026 100644
--- a/src/security/validity-period.cpp
+++ b/src/security/validity-period.cpp
@@ -94,23 +94,23 @@
ValidityPeriod::wireDecode(const Block& wire)
{
if (!wire.hasWire()) {
- throw Error("The supplied block does not contain wire format");
+ BOOST_THROW_EXCEPTION(Error("The supplied block does not contain wire format"));
}
m_wire = wire;
m_wire.parse();
if (m_wire.type() != tlv::ValidityPeriod)
- throw Error("Unexpected TLV type when decoding ValidityPeriod");
+ BOOST_THROW_EXCEPTION(Error("Unexpected TLV type when decoding ValidityPeriod"));
if (m_wire.elements_size() != 2)
- throw Error("Does not have two sub-TLVs");
+ BOOST_THROW_EXCEPTION(Error("Does not have two sub-TLVs"));
if (m_wire.elements()[NOT_BEFORE_OFFSET].type() != tlv::NotBefore ||
m_wire.elements()[NOT_BEFORE_OFFSET].value_size() != ISO_DATETIME_SIZE ||
m_wire.elements()[NOT_AFTER_OFFSET].type() != tlv::NotAfter ||
m_wire.elements()[NOT_AFTER_OFFSET].value_size() != ISO_DATETIME_SIZE) {
- throw Error("Invalid NotBefore or NotAfter field");
+ BOOST_THROW_EXCEPTION(Error("Invalid NotBefore or NotAfter field"));
}
try {
@@ -120,7 +120,7 @@
time::fromIsoString(readString(m_wire.elements()[NOT_AFTER_OFFSET])));
}
catch (const std::bad_cast&) {
- throw Error("Invalid date format in NOT-BEFORE or NOT-AFTER field");
+ BOOST_THROW_EXCEPTION(Error("Invalid date format in NOT-BEFORE or NOT-AFTER field"));
}
}