Refactor to standard layout.

This commit is contained in:
Kyle Isom 2023-10-19 20:41:55 -07:00
parent 0d7a91b69c
commit 59e6abff06
15 changed files with 40 additions and 39 deletions

View File

@ -1,3 +1,3 @@
<component name="DependencyValidationManager"> <component name="DependencyValidationManager">
<scope name="ProjectSources" pattern="file[emsha]:emsha/*||file:hmac.cc||file:emsha.cc||file:sha256.cc" /> <scope name="ProjectSources" pattern="file[emsha]:include/emsha/*||file:hmac.cc||file:emsha.cc||file:sha256.cc" />
</component> </component>

View File

@ -46,13 +46,13 @@ endif ()
### Set up the build ### ### Set up the build ###
set(HEADERS set(HEADERS
emsha/emsha.h include/emsha/emsha.h
emsha/sha256.h include/emsha/sha256.h
emsha/hmac.h include/emsha/hmac.h
emsha/internal.h) include/emsha/internal.h)
set(SOURCES emsha.cc sha256.cc hmac.cc) set(SOURCES src/emsha.cc src/sha256.cc src/hmac.cc)
include_directories(SYSTEM .) include_directories(include)
### Build products ### ### Build products ###
@ -60,14 +60,15 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
### TESTS ### ### TESTS ###
set(TEST_SOURCES test_utils.cc) set(TEST_SOURCES test/test_utils.cc)
macro(generate_test name) 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_link_libraries(${name} ${PROJECT_NAME})
target_include_directories(${name} PRIVATE test)
add_test(${name} ${name}) add_test(${name} ${name})
endmacro() endmacro()
generate_test(test_${PROJECT_NAME} test_${PROJECT_NAME}.cc) generate_test(test_${PROJECT_NAME})
generate_test(test_hmac) generate_test(test_hmac)
generate_test(test_mem) generate_test(test_mem)
generate_test(test_sha256) generate_test(test_sha256)

View File

@ -54,37 +54,37 @@ namespace emsha {
#endif #endif
/// SHA256_HASH_SIZE is the output length of SHA-256 in bytes. /// 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. /// \brief Describe the result of an EMSHA operation.
/// ///
/// The EMSHAResult type is used to indicate whether an operation /// The EMSHAResult type is used to indicate whether an operation
/// succeeded, and if not, what the general fault type was. /// 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 /// An unknown fault occurred. This is a serious bug in the
/// program. /// program.
Unknown = 0, Unknown = 0U,
/// All operations have completed successfully so far. /// All operations have completed successfully so far.
OK = 1, OK = 1U,
/// The self-test failed. /// The self-test failed.
TestFailure = 2, TestFailure = 2U,
/// A null pointer was passed in as a buffer where it shouldn't /// A null pointer was passed in as a buffer where it shouldn't
/// have been. /// have been.
NullPointer = 3, NullPointer = 3U,
/// The Hash is in an invalid state. /// The Hash is in an invalid state.
InvalidState = 4, InvalidState = 4U,
/// The input to SHA256::update is too large. /// The input to SHA256::update is too large.
InputTooLong = 5, InputTooLong = 5U,
/// The self tests have been disabled, but a self-test function /// The self tests have been disabled, but a self-test function
/// was called. /// was called.
SelfTestDisabled = 6 SelfTestDisabled = 6U
} ; } ;

View File

@ -33,8 +33,8 @@
#include <cstdint> #include <cstdint>
#include <emsha/emsha.h>
#include <array> #include <array>
#include <emsha/emsha.h>
namespace emsha { namespace emsha {

View File

@ -28,7 +28,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <emsha/emsha.h> #include "emsha/emsha.h"
using std::uint8_t; using std::uint8_t;

View File

@ -28,9 +28,9 @@
#include <cstdint> #include <cstdint>
#include <emsha/emsha.h> #include "emsha/emsha.h"
#include <emsha/sha256.h> #include "emsha/hmac.h"
#include <emsha/hmac.h> #include "emsha/sha256.h"
namespace emsha { namespace emsha {

View File

@ -27,9 +27,9 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <emsha/emsha.h> #include "emsha/emsha.h"
#include <emsha/sha256.h> #include "emsha/internal.h"
#include <emsha/internal.h> #include "emsha/sha256.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>

View File

@ -23,9 +23,9 @@
*/ */
#include "emsha/emsha.h"
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <emsha/emsha.h>
#include "test_utils.h" #include "test_utils.h"

View File

@ -25,8 +25,8 @@
#include <iostream> #include <iostream>
#include <emsha/emsha.h> #include "emsha/emsha.h"
#include <emsha/hmac.h> #include "emsha/hmac.h"
#include "test_utils.h" #include "test_utils.h"

View File

@ -35,9 +35,9 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <emsha/emsha.h> #include "emsha/emsha.h"
#include <emsha/sha256.h> #include "emsha/hmac.h"
#include <emsha/hmac.h> #include "emsha/sha256.h"
// Number of test iterations. // Number of test iterations.

View File

@ -23,9 +23,9 @@
*/ */
#include <iostream> #include "emsha/sha256.h"
#include <emsha/sha256.h>
#include <cassert> #include <cassert>
#include <iostream>
#include "test_utils.h" #include "test_utils.h"

View File

@ -30,9 +30,9 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <emsha/emsha.h> #include "emsha/emsha.h"
#include <emsha/sha256.h> #include "emsha/hmac.h"
#include <emsha/hmac.h> #include "emsha/sha256.h"
// How many times should a test result be checked? The goal is to // How many times should a test result be checked? The goal is to