tools: ndnsec-delete reports success or failure

Change-Id: I9b53fcc030fbca34acdf0c7dc3afc8ae8e8d523d
Refs: #2275
diff --git a/src/security/key-chain.cpp b/src/security/key-chain.cpp
index 9360671..758c2f5 100644
--- a/src/security/key-chain.cpp
+++ b/src/security/key-chain.cpp
@@ -679,32 +679,12 @@
 void
 KeyChain::deleteCertificate(const Name& certificateName)
 {
-  try
-    {
-      if (m_pib->getDefaultCertificateName() == certificateName)
-        return;
-    }
-  catch (SecPublicInfo::Error& e)
-    {
-      // Not a real error, just try to delete the certificate
-    }
-
   m_pib->deleteCertificateInfo(certificateName);
 }
 
 void
 KeyChain::deleteKey(const Name& keyName)
 {
-  try
-    {
-      if (m_pib->getDefaultKeyNameForIdentity(m_pib->getDefaultIdentity()) == keyName)
-        return;
-    }
-  catch (SecPublicInfo::Error& e)
-    {
-      // Not a real error, just try to delete the key
-    }
-
   m_pib->deletePublicKeyInfo(keyName);
   m_tpm->deleteKeyPairInTpm(keyName);
 }
@@ -712,25 +692,14 @@
 void
 KeyChain::deleteIdentity(const Name& identity)
 {
-  try
-    {
-      if (m_pib->getDefaultIdentity() == identity)
-        return;
-    }
-  catch (SecPublicInfo::Error& e)
-    {
-      // Not a real error, just try to delete the identity
-    }
-
-  std::vector<Name> nameList;
-  m_pib->getAllKeyNamesOfIdentity(identity, nameList, true);
-  m_pib->getAllKeyNamesOfIdentity(identity, nameList, false);
+  std::vector<Name> keyNames;
+  m_pib->getAllKeyNamesOfIdentity(identity, keyNames, true);
+  m_pib->getAllKeyNamesOfIdentity(identity, keyNames, false);
 
   m_pib->deleteIdentityInfo(identity);
 
-  std::vector<Name>::const_iterator it = nameList.begin();
-  for(; it != nameList.end(); it++)
-    m_tpm->deleteKeyPairInTpm(*it);
+  for (const auto& keyName : keyNames)
+    m_tpm->deleteKeyPairInTpm(keyName);
 }
 
 }
diff --git a/src/security/key-chain.hpp b/src/security/key-chain.hpp
index 28de735..1973c77 100644
--- a/src/security/key-chain.hpp
+++ b/src/security/key-chain.hpp
@@ -278,10 +278,8 @@
   /**
    * @brief delete a certificate.
    *
-   * If the certificate to be deleted is current default system default,
-   * the method will not delete the certificate and return immediately.
-   *
    * @param certificateName The certificate to be deleted.
+   * @throws KeyChain::Error if certificate cannot be deleted.
    */
   void
   deleteCertificate(const Name& certificateName);
@@ -289,10 +287,8 @@
   /**
    * @brief delete a key.
    *
-   * If the key to be deleted is current default system default,
-   * the method will not delete the key and return immediately.
-   *
    * @param keyName The key to be deleted.
+   * @throws KeyChain::Error if key cannot be deleted.
    */
   void
   deleteKey(const Name& keyName);
@@ -300,10 +296,8 @@
   /**
    * @brief delete an identity.
    *
-   * If the identity to be deleted is current default system default,
-   * the method will not delete the identity and return immediately.
-   *
    * @param identity The identity to be deleted.
+   * @throws KeyChain::Error if identity cannot be deleted.
    */
   void
   deleteIdentity(const Name& identity);