security: merge SIGNER_TYPE_PIB_* into SIGNER_TYPE_ID and SIGNER_TYPE_KEY
refs #3932
Change-Id: I73d2f479567e590fa3fa60d035b9275b69043b3e
diff --git a/src/security/v2/key-chain.cpp b/src/security/v2/key-chain.cpp
index 47cb75d..954231c 100644
--- a/src/security/v2/key-chain.cpp
+++ b/src/security/v2/key-chain.cpp
@@ -603,26 +603,32 @@
break;
}
case SigningInfo::SIGNER_TYPE_ID: {
- try {
- identity = m_pib->getIdentity(params.getSignerName());
- }
- catch (const Pib::Error&) {
- BOOST_THROW_EXCEPTION(InvalidSigningInfoError("Signing identity `" +
- params.getSignerName().toUri() + "` does not exist"));
+ identity = params.getPibIdentity();
+ if (!identity) {
+ try {
+ identity = m_pib->getIdentity(params.getSignerName());
+ }
+ catch (const Pib::Error&) {
+ BOOST_THROW_EXCEPTION(InvalidSigningInfoError("Signing identity `" +
+ params.getSignerName().toUri() + "` does not exist"));
+ }
}
break;
}
case SigningInfo::SIGNER_TYPE_KEY: {
- Name identityName = extractIdentityFromKeyName(params.getSignerName());
+ key = params.getPibKey();
+ if (!key) {
+ Name identityName = extractIdentityFromKeyName(params.getSignerName());
- try {
- identity = m_pib->getIdentity(identityName);
- key = identity.getKey(params.getSignerName());
- identity = Identity(); // we will use the PIB key instance, so reset identity;
- }
- catch (const Pib::Error&) {
- BOOST_THROW_EXCEPTION(InvalidSigningInfoError("Signing key `" +
- params.getSignerName().toUri() + "` does not exist"));
+ try {
+ identity = m_pib->getIdentity(identityName);
+ key = identity.getKey(params.getSignerName());
+ identity = Identity(); // we will use the PIB key instance, so reset identity;
+ }
+ catch (const Pib::Error&) {
+ BOOST_THROW_EXCEPTION(InvalidSigningInfoError("Signing key `" +
+ params.getSignerName().toUri() + "` does not exist"));
+ }
}
break;
}
@@ -645,18 +651,6 @@
sigInfo.setSignatureType(tlv::DigestSha256);
return std::make_tuple(SigningInfo::getDigestSha256Identity(), sigInfo);
}
- case SigningInfo::SIGNER_TYPE_PIB_ID: {
- identity = params.getPibIdentity();
- if (!identity)
- BOOST_THROW_EXCEPTION(InvalidSigningInfoError("PIB identity is invalid"));
- break;
- }
- case SigningInfo::SIGNER_TYPE_PIB_KEY: {
- key = params.getPibKey();
- if (!key)
- BOOST_THROW_EXCEPTION(InvalidSigningInfoError("PIB key is invalid"));
- break;
- }
default: {
BOOST_THROW_EXCEPTION(InvalidSigningInfoError("Unrecognized signer type " +
boost::lexical_cast<std::string>(params.getSignerType())));