diff --git a/.idea/scopes/ProjectSources.xml b/.idea/scopes/ProjectSources.xml index 15fa1f8..2e5fa13 100644 --- a/.idea/scopes/ProjectSources.xml +++ b/.idea/scopes/ProjectSources.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be2ab0..4b93e04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,14 +45,14 @@ else () endif () ### Set up the build ### -set(HEADERS - emsha/emsha.h - emsha/sha256.h - emsha/hmac.h - emsha/internal.h) -set(SOURCES emsha.cc sha256.cc hmac.cc) +set(HEADERS + include/emsha/emsha.h + include/emsha/sha256.h + include/emsha/hmac.h + include/emsha/internal.h) +set(SOURCES src/emsha.cc src/sha256.cc src/hmac.cc) -include_directories(SYSTEM .) +include_directories(include) ### Build products ### @@ -60,14 +60,15 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) ### TESTS ### -set(TEST_SOURCES test_utils.cc) +set(TEST_SOURCES test/test_utils.cc) macro(generate_test name) - add_executable(${name} ${name}.cc ${TEST_SOURCES} ${ARGN}) + add_executable(${name} test/${name}.cc ${TEST_SOURCES} ${ARGN}) target_link_libraries(${name} ${PROJECT_NAME}) + target_include_directories(${name} PRIVATE test) add_test(${name} ${name}) endmacro() -generate_test(test_${PROJECT_NAME} test_${PROJECT_NAME}.cc) +generate_test(test_${PROJECT_NAME}) generate_test(test_hmac) generate_test(test_mem) generate_test(test_sha256) diff --git a/emsha/emsha.h b/include/emsha/emsha.h similarity index 96% rename from emsha/emsha.h rename to include/emsha/emsha.h index a4a2b3a..55441c0 100644 --- a/emsha/emsha.h +++ b/include/emsha/emsha.h @@ -54,37 +54,37 @@ namespace emsha { #endif /// SHA256_HASH_SIZE is the output length of SHA-256 in bytes. -const std::uint32_t SHA256_HASH_SIZE = 32; +const std::uint32_t SHA256_HASH_SIZE = 32U; /// \brief Describe the result of an EMSHA operation. /// /// The EMSHAResult type is used to indicate whether an operation /// succeeded, and if not, what the general fault type was. -typedef enum class EMSHAResult : std::uint8_t { +enum class EMSHAResult : std::uint8_t { /// An unknown fault occurred. This is a serious bug in the /// program. - Unknown = 0, + Unknown = 0U, /// All operations have completed successfully so far. - OK = 1, + OK = 1U, /// The self-test failed. - TestFailure = 2, + TestFailure = 2U, /// A null pointer was passed in as a buffer where it shouldn't /// have been. - NullPointer = 3, + NullPointer = 3U, /// The Hash is in an invalid state. - InvalidState = 4, + InvalidState = 4U, /// The input to SHA256::update is too large. - InputTooLong = 5, + InputTooLong = 5U, /// The self tests have been disabled, but a self-test function /// was called. - SelfTestDisabled = 6 + SelfTestDisabled = 6U } ; diff --git a/emsha/hmac.h b/include/emsha/hmac.h similarity index 100% rename from emsha/hmac.h rename to include/emsha/hmac.h diff --git a/emsha/internal.h b/include/emsha/internal.h similarity index 100% rename from emsha/internal.h rename to include/emsha/internal.h diff --git a/emsha/sha256.h b/include/emsha/sha256.h similarity index 100% rename from emsha/sha256.h rename to include/emsha/sha256.h index b781909..61b0795 100644 --- a/emsha/sha256.h +++ b/include/emsha/sha256.h @@ -33,8 +33,8 @@ #include -#include #include +#include namespace emsha { diff --git a/emsha.cc b/src/emsha.cc similarity index 99% rename from emsha.cc rename to src/emsha.cc index f89c581..1f0652c 100644 --- a/emsha.cc +++ b/src/emsha.cc @@ -28,7 +28,7 @@ #include #include -#include +#include "emsha/emsha.h" using std::uint8_t; diff --git a/hmac.cc b/src/hmac.cc similarity index 98% rename from hmac.cc rename to src/hmac.cc index 20e2695..fcd1bf9 100644 --- a/hmac.cc +++ b/src/hmac.cc @@ -28,9 +28,9 @@ #include -#include -#include -#include +#include "emsha/emsha.h" +#include "emsha/hmac.h" +#include "emsha/sha256.h" namespace emsha { diff --git a/sha256.cc b/src/sha256.cc similarity index 99% rename from sha256.cc rename to src/sha256.cc index ffa8a00..4eaf022 100644 --- a/sha256.cc +++ b/src/sha256.cc @@ -27,9 +27,9 @@ #include #include -#include -#include -#include +#include "emsha/emsha.h" +#include "emsha/internal.h" +#include "emsha/sha256.h" #include #include diff --git a/test_emsha.cc b/test/test_emsha.cc similarity index 99% rename from test_emsha.cc rename to test/test_emsha.cc index 34f4dda..124a4e3 100644 --- a/test_emsha.cc +++ b/test/test_emsha.cc @@ -23,9 +23,9 @@ */ +#include "emsha/emsha.h" #include #include -#include #include "test_utils.h" diff --git a/test_hmac.cc b/test/test_hmac.cc similarity index 98% rename from test_hmac.cc rename to test/test_hmac.cc index a14500f..2f3abb0 100644 --- a/test_hmac.cc +++ b/test/test_hmac.cc @@ -25,8 +25,8 @@ #include -#include -#include +#include "emsha/emsha.h" +#include "emsha/hmac.h" #include "test_utils.h" diff --git a/test_mem.cc b/test/test_mem.cc similarity index 98% rename from test_mem.cc rename to test/test_mem.cc index 047f0c6..5b10024 100644 --- a/test_mem.cc +++ b/test/test_mem.cc @@ -35,9 +35,9 @@ #include #include -#include -#include -#include +#include "emsha/emsha.h" +#include "emsha/hmac.h" +#include "emsha/sha256.h" // Number of test iterations. diff --git a/test_sha256.cc b/test/test_sha256.cc similarity index 99% rename from test_sha256.cc rename to test/test_sha256.cc index badfffb..5ffd758 100644 --- a/test_sha256.cc +++ b/test/test_sha256.cc @@ -23,9 +23,9 @@ */ -#include -#include +#include "emsha/sha256.h" #include +#include #include "test_utils.h" diff --git a/test_utils.cc b/test/test_utils.cc similarity index 100% rename from test_utils.cc rename to test/test_utils.cc diff --git a/test_utils.h b/test/test_utils.h similarity index 97% rename from test_utils.h rename to test/test_utils.h index 74783c7..0ee794c 100644 --- a/test_utils.h +++ b/test/test_utils.h @@ -30,9 +30,9 @@ #include #include -#include -#include -#include +#include "emsha/emsha.h" +#include "emsha/hmac.h" +#include "emsha/sha256.h" // How many times should a test result be checked? The goal is to