diff --git a/CMakeLists.txt b/CMakeLists.txt index b25351b..b51961a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,17 @@ option(TESTING "Build tests" OFF) option(CLANG_TIDY "Perform linting with clang-tidy" OFF) option(SANITIZERS "Enable sanitizers" OFF) option(NO_ALLOC "Build without needing an allocator" OFF) +option(NAMESPACE_SUFFIX "Namespace Suffix for CXX and CMake Export") + +if(NAMESPACE_SUFFIX) + set(SFRAME_CXX_NAMESPACE "sframe_${NAMESPACE_SUFFIX}" CACHE STRING "Top-level Namespace for CXX") + set(SFRAME_EXPORT_NAMESPACE "SFrame${NAMESPACE_SUFFIX}" CACHE STRING "Namespace for CMake Export") +else() + set(SFRAME_CXX_NAMESPACE "sframe" CACHE STRING "Top-level Namespace for CXX") + set(SFRAME_EXPORT_NAMESPACE "SFrame" CACHE STRING "Namespace for CMake Export") +endif() +message(STATUS "CXX Namespace: ${SFRAME_CXX_NAMESPACE}") +message(STATUS "CMake Export Namespace: ${SFRAME_EXPORT_NAMESPACE}") # Use -DCRYPTO=(OPENSSL_1_1 | OPENSSL_3 | BORINGSSL) to configure crypto if(NOT DEFINED CRYPTO) @@ -20,6 +31,12 @@ endif() ### set_property(GLOBAL PROPERTY USE_FOLDERS ON) +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/namespace.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/namespace.h" + @ONLY +) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -87,13 +104,15 @@ endif() set(LIB_NAME "${PROJECT_NAME}") file(GLOB_RECURSE LIB_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB_RECURSE LIB_GENERATED_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/*.h") file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") -add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_SOURCES}) +add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_GENERATED_HEADERS} ${LIB_SOURCES}) target_link_libraries(${LIB_NAME} PRIVATE ${CRYPTO_LIB}) target_include_directories(${LIB_NAME} PUBLIC - $ + $ + $ $ ) diff --git a/cmake/namespace.h.in b/cmake/namespace.h.in new file mode 100644 index 0000000..8af8a45 --- /dev/null +++ b/cmake/namespace.h.in @@ -0,0 +1,4 @@ +#pragma once + +// Configurable top-level namespace +#define SFRAME_NAMESPACE @SFRAME_CXX_NAMESPACE@ diff --git a/include/sframe/map.h b/include/sframe/map.h index b404181..58d16aa 100644 --- a/include/sframe/map.h +++ b/include/sframe/map.h @@ -4,7 +4,7 @@ #include -namespace sframe { +namespace SFRAME_NAMESPACE { template class map : private vector>, N> @@ -69,13 +69,14 @@ class map : private vector>, N> } }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE #else // ifdef NO_ALLOC #include +#include -namespace sframe { +namespace SFRAME_NAMESPACE { // NOTE: NOT RECOMMENDED FOR USE OUTSIDE THIS LIBRARY // @@ -106,6 +107,6 @@ class map : public std::map } }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE #endif // def NO_ALLOC diff --git a/include/sframe/sframe.h b/include/sframe/sframe.h index ba38e2a..dcceb72 100644 --- a/include/sframe/sframe.h +++ b/include/sframe/sframe.h @@ -6,6 +6,8 @@ #include #include +#include + // These constants define the size of certain internal data structures if // we are configured not to depend on dynamic allocations, i.e., if the NO_ALLOC // flag is set. If you are using an allocator, you can ignore them. @@ -22,7 +24,7 @@ #define SFRAME_EPOCH_BITS 4 #endif -namespace sframe { +namespace SFRAME_NAMESPACE { struct crypto_error : std::runtime_error { @@ -202,4 +204,4 @@ class MLSContext : protected Context vector, max_epochs> epoch_cache; }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/include/sframe/vector.h b/include/sframe/vector.h index 649d2c3..79f23e0 100644 --- a/include/sframe/vector.h +++ b/include/sframe/vector.h @@ -1,10 +1,11 @@ #pragma once #include +#include #ifdef NO_ALLOC -namespace sframe { +namespace SFRAME_NAMESPACE { template class vector @@ -86,13 +87,13 @@ class vector operator gsl::span() { return gsl::span(_data).first(_size); } }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE #else // ifdef NO_ALLOC #include -namespace sframe { +namespace SFRAME_NAMESPACE { // NOTE: NOT RECOMMENDED FOR USE OUTSIDE THIS LIBRARY // @@ -137,6 +138,6 @@ class vector : public std::vector } }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE #endif // def NO_ALLOC diff --git a/src/crypto.cpp b/src/crypto.cpp index 92f9ca0..d5ca11f 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -1,7 +1,7 @@ #include "crypto.h" #include "header.h" -namespace sframe { +namespace SFRAME_NAMESPACE { size_t cipher_digest_size(CipherSuite suite) @@ -94,4 +94,4 @@ cipher_overhead(CipherSuite suite) } } -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/src/crypto.h b/src/crypto.h index b39b66d..eadd4bf 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -2,7 +2,7 @@ #include -namespace sframe { +namespace SFRAME_NAMESPACE { size_t cipher_digest_size(CipherSuite suite); @@ -48,4 +48,4 @@ open(CipherSuite suite, input_bytes aad, input_bytes ct); -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/src/crypto_boringssl.cpp b/src/crypto_boringssl.cpp index e6a4181..4bb6ba3 100644 --- a/src/crypto_boringssl.cpp +++ b/src/crypto_boringssl.cpp @@ -9,7 +9,7 @@ #include #include -namespace sframe { +namespace SFRAME_NAMESPACE { /// /// Convert between native identifiers / errors and OpenSSL ones @@ -428,6 +428,6 @@ open(CipherSuite suite, throw unsupported_ciphersuite_error(); } -} // namespace sframe +} // namespace SFRAME_NAMESPACE #endif // defined(OPENSSL_3) diff --git a/src/crypto_openssl11.cpp b/src/crypto_openssl11.cpp index b6f650a..d68e841 100644 --- a/src/crypto_openssl11.cpp +++ b/src/crypto_openssl11.cpp @@ -7,7 +7,7 @@ #include #include -namespace sframe { +namespace SFRAME_NAMESPACE { /// /// Scoped pointers for OpenSSL objects @@ -466,6 +466,6 @@ open(CipherSuite suite, throw unsupported_ciphersuite_error(); } -} // namespace sframe +} // namespace SFRAME_NAMESPACE #endif // defined(OPENSSL_1_1) diff --git a/src/crypto_openssl3.cpp b/src/crypto_openssl3.cpp index 6dea6bf..d1bda30 100644 --- a/src/crypto_openssl3.cpp +++ b/src/crypto_openssl3.cpp @@ -9,7 +9,7 @@ #include #include -namespace sframe { +namespace SFRAME_NAMESPACE { /// /// Convert between native identifiers / errors and OpenSSL ones @@ -468,6 +468,6 @@ open(CipherSuite suite, throw unsupported_ciphersuite_error(); } -} // namespace sframe +} // namespace SFRAME_NAMESPACE #endif // defined(OPENSSL_3) diff --git a/src/header.cpp b/src/header.cpp index ab4c46c..dcf022c 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -1,6 +1,6 @@ #include "header.h" -namespace sframe { +namespace SFRAME_NAMESPACE { static size_t uint_size(uint64_t val) @@ -200,4 +200,4 @@ Header::encode(output_bytes buffer) const } #endif -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/src/header.h b/src/header.h index f431d7d..2c881eb 100644 --- a/src/header.h +++ b/src/header.h @@ -2,7 +2,7 @@ #include -namespace sframe { +namespace SFRAME_NAMESPACE { void encode_uint(uint64_t val, output_bytes buffer); @@ -31,4 +31,4 @@ class Header Header(KeyID key_id_in, Counter counter_in, input_bytes encoded_in); }; -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/src/sframe.cpp b/src/sframe.cpp index 6fc3ac3..7616bc1 100644 --- a/src/sframe.cpp +++ b/src/sframe.cpp @@ -3,7 +3,7 @@ #include "crypto.h" #include "header.h" -namespace sframe { +namespace SFRAME_NAMESPACE { /// /// Errors @@ -378,4 +378,4 @@ MLSContext::ensure_key(KeyID key_id, KeyUsage usage) return; } -} // namespace sframe +} // namespace SFRAME_NAMESPACE diff --git a/test/common.cpp b/test/common.cpp index 3d1ea82..0fa3921 100644 --- a/test/common.cpp +++ b/test/common.cpp @@ -21,7 +21,7 @@ from_hex(const std::string& hex) } std::string -to_hex(const sframe::input_bytes data) +to_hex(const SFRAME_NAMESPACE::input_bytes data) { std::stringstream hex(std::ios_base::out); hex.flags(std::ios::hex); diff --git a/test/common.h b/test/common.h index 8b13c03..ad40edf 100644 --- a/test/common.h +++ b/test/common.h @@ -1,3 +1,4 @@ +#include #include #include @@ -8,7 +9,7 @@ using bytes = std::vector; bytes from_hex(const std::string& hex); std::string -to_hex(const sframe::input_bytes data); +to_hex(const SFRAME_NAMESPACE::input_bytes data); template bytes diff --git a/test/header.cpp b/test/header.cpp index c6ce8f1..7c8cab1 100644 --- a/test/header.cpp +++ b/test/header.cpp @@ -9,7 +9,7 @@ #include // for map #include // for invalid_argument -using namespace sframe; +using namespace SFRAME_NAMESPACE; TEST_CASE("Header Known-Answer") { diff --git a/test/sframe.cpp b/test/sframe.cpp index ed59e15..0200634 100644 --- a/test/sframe.cpp +++ b/test/sframe.cpp @@ -10,7 +10,7 @@ #include // for invalid_argument #include // for basic_string, operator== -using namespace sframe; +using namespace SFRAME_NAMESPACE; TEST_CASE("SFrame Round-Trip") { diff --git a/test/vectors.cpp b/test/vectors.cpp index ac9adc1..a3e1c45 100644 --- a/test/vectors.cpp +++ b/test/vectors.cpp @@ -8,7 +8,7 @@ #include "common.h" -using namespace sframe; +using namespace SFRAME_NAMESPACE; using nlohmann::json; struct HexBytes