security: Correct code style for ndnsec and add command-line exception handling
Change-Id: I68de24c3fb2af5decd57b790ccbfc908dc0c8332
diff --git a/tools/ndnsec-set-acl.hpp b/tools/ndnsec-set-acl.hpp
index 2d64aca..7851322 100644
--- a/tools/ndnsec-set-acl.hpp
+++ b/tools/ndnsec-set-acl.hpp
@@ -16,11 +16,11 @@
using namespace ndn;
namespace po = boost::program_options;
- std::string keyName;
+ std::string keyName;
std::string appPath;
- po::options_description desc("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options");
- desc.add_options()
+ po::options_description description("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options");
+ description.add_options()
("help,h", "produce help message")
("keyName,k", po::value<std::string>(&keyName), "Key name.")
("appPath,p", po::value<std::string>(&appPath), "Application path.")
@@ -33,39 +33,39 @@
po::variables_map vm;
try
{
- po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
+ po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(),
+ vm);
po::notify(vm);
}
- catch (std::exception &e)
+ catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
- if (vm.count("help"))
+ if (vm.count("help") != 0)
{
- std::cerr << desc << std::endl;
+ std::cerr << description << std::endl;
return 0;
}
- try
+ if (vm.count("keyName") == 0)
{
- KeyChain keyChain;
- keyChain.addAppToACL(keyName, KEY_CLASS_PRIVATE, appPath, ACL_TYPE_PRIVATE);
-
- }
- catch(const SecTpm::Error& e)
- {
- std::cerr << e.what() << std::endl;
- return 1;
- }
- catch(const SecPublicInfo::Error& e)
- {
- std::cerr << e.what() << std::endl;
+ std::cerr << "ERROR: keyName is required!" << std::endl;
+ std::cerr << description << std::endl;
return 1;
}
-
+ if (vm.count("appPath") == 0)
+ {
+ std::cerr << "ERROR: appPath is required!" << std::endl;
+ std::cerr << description << std::endl;
+ return 1;
+ }
+
+ KeyChain keyChain;
+ keyChain.addAppToACL(keyName, KEY_CLASS_PRIVATE, appPath, ACL_TYPE_PRIVATE);
+
return 0;
}