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/util.cpp b/tools/ndnsec/util.cpp
new file mode 100644
index 0000000..7afa036
--- /dev/null
+++ b/tools/ndnsec/util.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "util.hpp"
+
+namespace ndn {
+namespace ndnsec {
+
+bool
+getPassword(std::string& password, const std::string& prompt)
+{
+#ifdef NDN_CXX_HAVE_GETPASS
+  bool isReady = false;
+
+  char* pw0 = nullptr;
+
+  pw0 = getpass(prompt.c_str());
+  if (!pw0)
+    return false;
+  std::string password1 = pw0;
+  memset(pw0, 0, strlen(pw0));
+
+  pw0 = getpass("Confirm:");
+  if (!pw0) {
+    char* pw1 = const_cast<char*>(password1.c_str());
+    memset(pw1, 0, password1.size());
+    return false;
+  }
+
+  if (!password1.compare(pw0)) {
+    isReady = true;
+    password.swap(password1);
+  }
+
+  char* pw1 = const_cast<char*>(password1.c_str());
+  memset(pw1, 0, password1.size());
+  memset(pw0, 0, strlen(pw0));
+
+  if (password.empty())
+    return false;
+
+  return isReady;
+#else
+  return false;
+#endif // NDN_CXX_HAVE_GETPASS
+}
+
+shared_ptr<security::v1::IdentityCertificate>
+getIdentityCertificate(const std::string& fileName)
+{
+  if (fileName == "-")
+    return io::load<security::v1::IdentityCertificate>(std::cin);
+  else
+    return io::load<security::v1::IdentityCertificate>(fileName);
+}
+
+} // namespace ndnsec
+} // namespace ndn