management: simplify CommandOptions with SigningInfo

Signing parameter in ndn::nfd::CommandOptions is now using
ndn::security::SigningInfo. Old signing parameter APIs are deprecated.

refs #2893

Change-Id: I81831fecd382efa369792218ac5457690d4c4046
diff --git a/src/management/nfd-command-options.cpp b/src/management/nfd-command-options.cpp
index f8141d3..97a1be8 100644
--- a/src/management/nfd-command-options.cpp
+++ b/src/management/nfd-command-options.cpp
@@ -21,6 +21,11 @@
 
 #include "nfd-command-options.hpp"
 
+#ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
+#include "../security/identity-certificate.hpp"
+#include "../security/signing-helpers.hpp"
+#endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
+
 namespace ndn {
 namespace nfd {
 
@@ -30,7 +35,6 @@
 CommandOptions::CommandOptions()
   : m_timeout(DEFAULT_TIMEOUT)
   , m_prefix(DEFAULT_PREFIX)
-  , m_signingParamsKind(SIGNING_PARAMS_DEFAULT)
 {
 }
 
@@ -53,10 +57,54 @@
 }
 
 CommandOptions&
+CommandOptions::setSigningInfo(const security::SigningInfo& signingInfo)
+{
+  m_signingInfo = signingInfo;
+  return *this;
+}
+
+#ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
+
+CommandOptions::SigningParamsKind
+CommandOptions::getSigningParamsKind() const
+{
+  switch (m_signingInfo.getSignerType()) {
+  case security::SigningInfo::SIGNER_TYPE_NULL:
+    return SIGNING_PARAMS_DEFAULT;
+  case security::SigningInfo::SIGNER_TYPE_ID:
+    return SIGNING_PARAMS_IDENTITY;
+  case security::SigningInfo::SIGNER_TYPE_CERT:
+    return SIGNING_PARAMS_CERTIFICATE;
+  default:
+    throw std::out_of_range("SigningInfo::SignerType is not convertible to CommandOptions::SigningParamsKind");
+  }
+}
+
+const Name&
+CommandOptions::getSigningIdentity() const
+{
+  BOOST_ASSERT(m_signingInfo.getSignerType() == security::SigningInfo::SIGNER_TYPE_ID);
+  return m_signingInfo.getSignerName();
+}
+
+const Name&
+CommandOptions::getSigningCertificate() const
+{
+  BOOST_ASSERT(m_signingInfo.getSignerType() == security::SigningInfo::SIGNER_TYPE_CERT);
+  return m_signingInfo.getSignerName();
+}
+
+CommandOptions&
+CommandOptions::setSigningDefault()
+{
+  m_signingInfo = security::SigningInfo();
+  return *this;
+}
+
+CommandOptions&
 CommandOptions::setSigningIdentity(const Name& identityName)
 {
-  m_signingParamsKind = SIGNING_PARAMS_IDENTITY;
-  m_identity = identityName;
+  m_signingInfo = security::signingByIdentity(identityName);
   return *this;
 }
 
@@ -69,8 +117,7 @@
     throw std::invalid_argument("certificate is invalid");
   }
 
-  m_signingParamsKind = SIGNING_PARAMS_CERTIFICATE;
-  m_identity = certificateName;
+  m_signingInfo = security::signingByCertificate(certificateName);
   return *this;
 }
 
@@ -80,5 +127,7 @@
   return this->setSigningCertificate(certificate.getName());
 }
 
+#endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
+
 } // namespace nfd
 } // namespace ndn