tools: Refactor ndnsec tools and update code style
This commit also deletes unused (broken) `op-tool`
Change-Id: I6c45c293d9c22198efd9db8144e32097d73738e5
Refs: #3098
diff --git a/tools/ndnsec/main.cpp b/tools/ndnsec/main.cpp
index 4dc7ee0..6a2572a 100644
--- a/tools/ndnsec/main.cpp
+++ b/tools/ndnsec/main.cpp
@@ -17,101 +17,70 @@
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
*/
+#include "ndnsec.hpp"
+#include "util.hpp"
#include "version.hpp"
-#include "security/v1/key-chain.hpp"
-#include "security/v1/certificate-subject-description.hpp"
-#include "security/v1/secured-bag.hpp"
-
-#include "util.hpp"
-#include "list.hpp"
-#include "get-default.hpp"
-#include "set-default.hpp"
-#include "key-gen.hpp"
-#include "dsk-gen.hpp"
-#include "sign-req.hpp"
-#include "cert-gen.hpp"
-#include "cert-revoke.hpp"
-#include "cert-dump.hpp"
-#include "cert-install.hpp"
-#include "export.hpp"
-#include "import.hpp"
-#include "delete.hpp"
-#include "set-acl.hpp"
-#include "unlock-tpm.hpp"
-#include "op-tool.hpp"
-
-using namespace ndn;
-using namespace ndn::security;
-using namespace ndn::security::v1;
-
-std::string ndnsec_helper("\
- help Show all commands.\n\
- version Show version and exit.\n\
- list Display information in PublicInfo.\n\
- 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-revoke Revoke an identity certificate.\n\
- cert-dump Dump a certificate from PublicInfo.\n\
- cert-install Install a certificate into PublicInfo.\n\
- delete Delete identity/key/certificate.\n\
- export Export an identity package.\n\
- import Import an identity package.\n\
- set-acl Configure ACL of a private key.\n\
- unlock-tpm Unlock Tpm.\n\
- op-tool Operator tool.\n\
-");
+std::string ndnsec_helper = R"STR(
+ help Show all commands
+ version Show version and exit
+ list Display information in PublicInfo
+ get-default Get default setting info
+ set-default Configure default setting
+ key-gen Generate a Key-Signing-Key for an identity
+ dsk-gen Generate a Data-Signing-Key for an identity
+ sign-req Generate a certificate signing request
+ cert-gen Generate an identity certificate
+ cert-revoke Revoke an identity certificate
+ cert-dump Dump a certificate from PublicInfo
+ cert-install Install a certificate into PublicInfo
+ delete Delete identity/key/certificate
+ export Export an identity package
+ import Import an identity package
+ set-acl Configure ACL of a private key
+ unlock-tpm Unlock Tpm
+)STR";
int
main(int argc, char** argv)
{
- if (argc < 2)
- {
+ if (argc < 2) {
+ std::cerr << ndnsec_helper << std::endl;
+ return 1;
+ }
+
+ using namespace ndn::ndnsec;
+
+ std::string command(argv[1]);
+ try {
+ if (command == "help") { std::cout << ndnsec_helper << std::endl; }
+ else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING << 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-revoke") { return ndnsec_cert_revoke(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 == "set-acl") { return ndnsec_set_acl(argc - 1, argv + 1); }
+ else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
+ else {
std::cerr << ndnsec_helper << std::endl;
return 1;
}
-
- std::string command(argv[1]);
-
- try
- {
- if (command == "help") { std::cout << ndnsec_helper << std::endl; }
- else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING
- << 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-revoke") { return ndnsec_cert_revoke(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 == "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;
- }
+ }
+ catch (const std::runtime_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ return 1;
+ }
return 0;
}