From 70dfabd967048c0df4acc4702a373869c0fe03e7 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Fri, 1 Nov 2024 08:02:46 -0400 Subject: [PATCH] Minor fixes (#435) * Link nlohmann_json at the top level * Clean up TLS syntax library's use of integer types * clang-format --- CMakeLists.txt | 9 ++++++++- lib/hpke/test/build.cpp | 20 ++++++++++---------- lib/tls_syntax/include/tls/tls_syntax.h | 13 +++++++++++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eddb1c5d..6be0cc58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,9 @@ set(VCPKG_BUILD_TYPE release) # Internal libraries add_subdirectory(lib) +# External libraries +find_package(nlohmann_json REQUIRED) + # Third-Party libraries in tree add_subdirectory(third_party) @@ -118,7 +121,11 @@ file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_SOURCES}) add_dependencies(${LIB_NAME} bytes tls_syntax hpke) -target_link_libraries(${LIB_NAME} bytes tls_syntax hpke) +target_link_libraries(${LIB_NAME} + PRIVATE + nlohmann_json::nlohmann_json + PUBLIC + bytes tls_syntax hpke) target_include_directories(${LIB_NAME} PUBLIC $ diff --git a/lib/hpke/test/build.cpp b/lib/hpke/test/build.cpp index d1edc2e1..4bf9c1c5 100644 --- a/lib/hpke/test/build.cpp +++ b/lib/hpke/test/build.cpp @@ -3,16 +3,16 @@ TEST_CASE("BoringSSL Define") { #if defined(__has_include) - #if __has_include() - #if defined(WITH_BORINGSSL) - REQUIRE(WITH_BORINGSSL); - #else - FAIL("Expect #WITH_BORINGSSL set when compiling with BoringSSL"); - #endif - #else - SKIP("Only applicable to BoringSSL"); - #endif +#if __has_include() +#if defined(WITH_BORINGSSL) + REQUIRE(WITH_BORINGSSL); #else - SKIP("Cannot ensure BoringSSL without __has_include()"); + FAIL("Expect #WITH_BORINGSSL set when compiling with BoringSSL"); +#endif +#else + SKIP("Only applicable to BoringSSL"); +#endif +#else + SKIP("Cannot ensure BoringSSL without __has_include()"); #endif } \ No newline at end of file diff --git a/lib/tls_syntax/include/tls/tls_syntax.h b/lib/tls_syntax/include/tls/tls_syntax.h index 1b3dd8c5..a5c87202 100644 --- a/lib/tls_syntax/include/tls/tls_syntax.h +++ b/lib/tls_syntax/include/tls/tls_syntax.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -14,6 +15,13 @@ namespace MLS_NAMESPACE::tls { +using std::ptrdiff_t; +using std::size_t; +using std::uint16_t; +using std::uint32_t; +using std::uint64_t; +using std::uint8_t; + // For indicating no min or max in vector definitions const size_t none = std::numeric_limits::max(); @@ -288,8 +296,9 @@ operator>>(istream& str, std::vector& vec) // NB: Remember that we store the vector in reverse order // NB: This requires that T be default-constructible istream r; + const auto size_diff = static_cast(size); r._buffer = - std::vector{ str._buffer.end() - size, str._buffer.end() }; + std::vector{ str._buffer.end() - size_diff, str._buffer.end() }; vec.clear(); while (r._buffer.size() > 0) { @@ -298,7 +307,7 @@ operator>>(istream& str, std::vector& vec) } // Truncate the primary buffer - str._buffer.erase(str._buffer.end() - size, str._buffer.end()); + str._buffer.erase(str._buffer.end() - size_diff, str._buffer.end()); return str; }