diff --git a/.drone.starlark b/.drone.starlark index 08c6c56..aa53a5f 100644 --- a/.drone.starlark +++ b/.drone.starlark @@ -5,11 +5,21 @@ def main(ctx): "type": "docker", "name": "testing", "steps": [ + { + "name": "update submodules", + "image": "docker.io/immawanderer/fedora-cpp:linux-amd64", + "pull": "always", + "depends_on": ["clone"], + "commands": [ + "uname -r", + "git submodule update --init --recursive" + ] + }, { "name": "cppcheck", "image": "docker.io/archlinux:base-devel", "pull": "always", - "depends_on": ["clone"], + "depends_on": ["update submodules"], "commands": [ "pacman -Sy cppcheck --noconfirm --needed", "uname -r", diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2e5371e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/fmt"] + path = lib/fmt + url = https://github.com/fmtlib/fmt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index f4ef6a9..5ece0fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,23 @@ project(fortuna LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +find_package(Git QUIET) +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Update submodule(s)") + message(STATUS "Current source dir: ${CMAKE_CURRENT_SOURCE_DIR}") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() +endif() + +add_subdirectory(lib/fmt EXCLUDE_FROM_ALL) + if(CMAKE_BUILD_TYPE MATCHES "Debug") # Produce debugging information in the operating system's native format. # Level 3 includes extra information, such as all the macro definitions @@ -99,4 +116,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() add_executable(fortuna main.cpp generator.cpp generator.h fortuna.cpp fortuna.h) -target_link_libraries(fortuna cryptopp) +# ref: https://cmake.org/pipermail/cmake/2016-May/063400.html +target_link_libraries(fortuna + PRIVATE cryptopp + PRIVATE fmt::fmt-header-only) diff --git a/fortuna.cpp b/fortuna.cpp index 8501348..915a438 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -9,10 +9,10 @@ #include #include #include +#include #include #include -#include namespace fortuna { @@ -46,7 +46,7 @@ namespace fortuna { std::string cipher, encoded_c, decrypted; try { - std::cout << "plain text: " << plain << std::endl; + fmt::print("plain text: {}\n", plain); CTR_Mode::Encryption e; e.SetKeyWithIV(key,key.size(),ctr); @@ -63,7 +63,7 @@ namespace fortuna { ); // StringSource } catch(CryptoPP::Exception& e) { - std::cerr << e.what() << std::endl; + fmt::print(stderr, "{}\n", e.what()); exit(1); } @@ -73,7 +73,7 @@ namespace fortuna { new StringSink(encoded_c) ) // HexEncoder ); // StringSource - std::cout << "cipher text: " << encoded_c << std::endl; + fmt::print("cipher text: {}\n", encoded_c); try { CTR_Mode::Decryption d; @@ -86,10 +86,10 @@ namespace fortuna { ) // StreamTransformationFilter ); // StringSource - std::cout << "decrypted text: " << decrypted << std::endl; + fmt::print("decrypted text: {}\n", decrypted); } catch(CryptoPP::Exception& e) { - std::cerr << e.what() << std::endl; + fmt::print(stderr, "{}\n", e.what()); exit(1); } diff --git a/generator.cpp b/generator.cpp index 4e1ca0b..aba46ca 100644 --- a/generator.cpp +++ b/generator.cpp @@ -5,11 +5,11 @@ #include #include #include -#include #include #include #include +#include #include "generator.h" @@ -69,7 +69,7 @@ auto Generator::do_sha(const std::string& k_n_s) -> std::string { new HashFilter(sha3_256,new HexEncoder(new StringSink(digest),false)) ); assert(digest == to_compare); - std::cout << digest << std::endl; + fmt::print("{}\n", digest); digest.erase(); // return digest; diff --git a/lib/fmt b/lib/fmt new file mode 160000 index 0000000..c089f7d --- /dev/null +++ b/lib/fmt @@ -0,0 +1 @@ +Subproject commit c089f7d497bcce35a0fd6da0512f8585ed1cc002 diff --git a/main.cpp b/main.cpp index 6928e08..54dd29a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,10 @@ -#include #include "fortuna.h" #include "generator.h" +#include + int main() { - using std::cout; - using std::endl; - cout << "[*] doing evil stuff" << endl; + fmt::print("[*] doing evil stuff\n"); fortuna::Fortuna f; f.random_data(4); return 0;