From 3c2c4c4328bd797979b27bdf98a4e7bbe5d2cb2c Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Wed, 30 Mar 2022 20:55:28 -0700 Subject: [PATCH] Remove absl dependency absl is only used in ukey2_shell test prog. Remove it and use getopt and unique_ptr array to reduce dependency --- .gitmodules | 4 -- CMakeLists.txt | 15 +---- README.md | 2 +- src/main/cpp/src/securegcm/CMakeLists.txt | 4 -- src/main/cpp/src/securegcm/ukey2_shell.cc | 68 +++++++++++++++++------ third_party/absl | 1 - 6 files changed, 55 insertions(+), 39 deletions(-) delete mode 160000 third_party/absl diff --git a/.gitmodules b/.gitmodules index 2624f19..9f9f98f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,3 @@ path = third_party/protobuf url = https://github.com/protocolbuffers/protobuf branch = master -[submodule "third_party/absl"] - path = third_party/absl - url = https://github.com/abseil/abseil-cpp - branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index b4d99a1..cdecab0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,19 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.0.2) +cmake_minimum_required(VERSION 3.1) # Do not install gtest since we are embedding googletest. option(INSTALL_GTEST "Do not install gtest since we are embedding googletest" OFF) project(ukey2) +set(CMAKE_CXX_STANDARD 11) + option(ukey2_USE_LOCAL_PROTOBUF "Use local copy of protobuf library and compiler" OFF) -option(ukey2_USE_LOCAL_ABSL - "Use local copy of abseil-cpp library" OFF) - option(BYPASS_TESTING "Do not build or run tests" OFF) @@ -35,14 +34,6 @@ if (ukey2_USE_LOCAL_PROTOBUF) include(cmake/local_build_protobuf.cmake) endif() -if (ukey2_USE_LOCAL_ABSL) - if (NOT TARGET absl::base) - add_subdirectory(third_party/absl) - endif() -else() - find_package(absl REQUIRED) -endif() - find_package(Protobuf REQUIRED) enable_testing() diff --git a/README.md b/README.md index fdca957..8400214 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ git submodule update --init --recursive ``` cd mkdir build; cd build -cmake -Dukey2_USE_LOCAL_PROTOBUF=ON -Dukey2_USE_LOCAL_ABSL=ON -DCMAKE_INSTALL_PREFIX=/tmp/ukey2_install .. +cmake -Dukey2_USE_LOCAL_PROTOBUF=ON -DCMAKE_INSTALL_PREFIX=/tmp/ukey2_install .. make make install ``` diff --git a/src/main/cpp/src/securegcm/CMakeLists.txt b/src/main/cpp/src/securegcm/CMakeLists.txt index 16feaea..541a7b2 100644 --- a/src/main/cpp/src/securegcm/CMakeLists.txt +++ b/src/main/cpp/src/securegcm/CMakeLists.txt @@ -40,8 +40,4 @@ target_link_libraries(ukey2_shell PUBLIC securemessage ukey2 - absl::base - absl::fixed_array - absl::flags - absl::flags_parse ) diff --git a/src/main/cpp/src/securegcm/ukey2_shell.cc b/src/main/cpp/src/securegcm/ukey2_shell.cc index 99a35a8..e35c263 100644 --- a/src/main/cpp/src/securegcm/ukey2_shell.cc +++ b/src/main/cpp/src/securegcm/ukey2_shell.cc @@ -39,21 +39,13 @@ #include #include +#include + #include "securegcm/ukey2_handshake.h" -#include "absl/container/fixed_array.h" -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" #define LOG(ERROR) std::cerr #define CHECK_EQ(a, b) do { if ((a) != (b)) abort(); } while(0) -ABSL_FLAG( - int, verification_string_length, 32, - "The length in bytes of the verification string. Must be a value between 1" - "and 32."); -ABSL_FLAG(string, mode, "initiator", - "The mode to run as: one of [initiator, responder]"); - namespace securegcm { namespace { @@ -86,10 +78,10 @@ string ReadFrame() { length |= static_cast(length_data[3]) << (0 * 8); // Read |length| bytes from the stream. - absl::FixedArray buffer(length); - CHECK_EQ(length, fread(buffer.data(), 1, length, stdin)); + std::unique_ptr buffer(new char[length]); + CHECK_EQ(length, fread(buffer.get(), 1, length, stdin)); - return string(buffer.data(), length); + return string(buffer.get(), length); } } // namespace @@ -271,11 +263,54 @@ bool UKey2Shell::RunAsResponder() { } // namespace securegcm +static void printUsage(char* name) { + std::string exec_name(name); + std::string usage( + + "ICACHE is a command-line based wrapper, exercising the\n" + "UKey2Handshake class. Its main use is to be run in a Java test, testing the\n" + "compatibility of the Java and C++ implementations.\n" + "\n" + "This program can be run in two modes, initiator or responder (default is\n" + "initiator):\n" + " ukey2_shell --mode=initiator --verification_string_length=32\n" + " ukey2_shell --mode=responder --verification_string_length=32\n" + ); + const std::string from("ICACHE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + printf("%s", usage.c_str()); +} + int main(int argc, char** argv) { - absl::ParseCommandLine(argc, argv); + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, 0, 'h' }, + { "mode", required_argument, 0, 'm' }, + { "verification_string_length", required_argument, 0, 'l' }, + { 0, 0, 0, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + int verification_string_length = 32; + string mode = "initiator"; + + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + return 0; + case 'l': + verification_string_length = atoi(optarg); + break; + case 'm': + mode = optarg; + break; + } + } - const int verification_string_length = - absl::GetFlag(FLAGS_verification_string_length); if (verification_string_length < 1 || verification_string_length > 32) { LOG(ERROR) << "Invalid flag value, verification_string_length: " << verification_string_length; @@ -284,7 +319,6 @@ int main(int argc, char** argv) { securegcm::UKey2Shell shell(verification_string_length); int exit_code = 0; - const string mode = absl::GetFlag(FLAGS_mode); if (mode == "initiator") { exit_code = !shell.RunAsInitiator(); } else if (mode == "responder") { diff --git a/third_party/absl b/third_party/absl deleted file mode 160000 index 278e0a0..0000000 --- a/third_party/absl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 278e0a071885a22dcd2fd1b5576cc44757299343