security: Correct code style for ndnsec and add command-line exception handling

Change-Id: I68de24c3fb2af5decd57b790ccbfc908dc0c8332
diff --git a/tools/ndnsec.cpp b/tools/ndnsec.cpp
index db1f50b..24026e0 100644
--- a/tools/ndnsec.cpp
+++ b/tools/ndnsec.cpp
@@ -31,7 +31,6 @@
   get-default  Get default setting info.\n\
   set-default  Configure default setting.\n\
   key-gen      Generate a Key-Signing-Key for an identity.\n\
-  dsk-gen      Generate a Data-Signing-Key for an identity.\n\
   sign-req     Generate a certificate signing request.\n\
   cert-gen     Generate an identity certificate.\n\
   cert-dump    Dump a certificate from PublicInfo.\n\
@@ -48,35 +47,42 @@
 int 
 main(int argc, char** argv)
 {
-  if (argc < 1)
+  if (argc < 2)
     {
       std::cerr << ndnsec_helper << std::endl;
       return 1;
     }
 
   std::string command(argv[1]);
-  
-  if (command == "help")              { std::cerr << ndnsec_helper << std::endl; }
-  else if (command == "list")         { return ndnsec_list(argc - 1, argv + 1); }
-  else if (command == "get-default")  { return ndnsec_get_default(argc - 1, argv + 1); }
-  else if (command == "set-default")  { return ndnsec_set_default(argc - 1, argv + 1); }
-  else if (command == "key-gen")      { return ndnsec_key_gen(argc - 1, argv + 1); }
-  else if (command == "dsk-gen")      { return ndnsec_dsk_gen(argc - 1, argv + 1); }
-  else if (command == "sign-req")     { return ndnsec_sign_req(argc - 1, argv + 1); }
-  else if (command == "cert-gen")     { return ndnsec_cert_gen(argc - 1, argv + 1); }
-  else if (command == "cert-dump")    { return ndnsec_cert_dump(argc - 1, argv + 1); }
-  else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
-  else if (command == "delete")       { return ndnsec_delete(argc - 1, argv + 1); }
-  else if (command == "export")       { return ndnsec_export(argc - 1, argv + 1); }
-  else if (command == "import")       { return ndnsec_import(argc - 1, argv + 1); }
-  else if (command == "sig-verify")   { return ndnsec_sig_verify(argc - 1, argv + 1); }
-  else if (command == "set-acl")      { return ndnsec_set_acl(argc - 1, argv + 1); }
-  else if (command == "unlock-tpm")   { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
-  else if (command == "op-tool")      { return ndnsec_op_tool(argc - 1, argv + 1); }
-  else {
-    std::cerr << ndnsec_helper << std::endl;
-    return 1;
-  }
+
+  try
+    {
+      if (command == "help")              { std::cerr << ndnsec_helper << std::endl; }
+      else if (command == "list")         { return ndnsec_list(argc - 1, argv + 1); }
+      else if (command == "get-default")  { return ndnsec_get_default(argc - 1, argv + 1); }
+      else if (command == "set-default")  { return ndnsec_set_default(argc - 1, argv + 1); }
+      else if (command == "key-gen")      { return ndnsec_key_gen(argc - 1, argv + 1); }
+      else if (command == "sign-req")     { return ndnsec_sign_req(argc - 1, argv + 1); }
+      else if (command == "cert-gen")     { return ndnsec_cert_gen(argc - 1, argv + 1); }
+      else if (command == "cert-dump")    { return ndnsec_cert_dump(argc - 1, argv + 1); }
+      else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
+      else if (command == "delete")       { return ndnsec_delete(argc - 1, argv + 1); }
+      else if (command == "export")       { return ndnsec_export(argc - 1, argv + 1); }
+      else if (command == "import")       { return ndnsec_import(argc - 1, argv + 1); }
+      else if (command == "sig-verify")   { return ndnsec_sig_verify(argc - 1, argv + 1); }
+      else if (command == "set-acl")      { return ndnsec_set_acl(argc - 1, argv + 1); }
+      else if (command == "unlock-tpm")   { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
+      else if (command == "op-tool")      { return ndnsec_op_tool(argc - 1, argv + 1); }
+      else {
+        std::cerr << ndnsec_helper << std::endl;
+        return 1;
+      }
+    }
+  catch (const std::runtime_error& e)
+    {
+      std::cerr << "ERROR: " << e.what() << std::endl;
+      return 1;
+    }
 
   return 0;
 }