Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ project(sframe
option(TESTING "Build tests" OFF)
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
option(SANITIZERS "Enable sanitizers" 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)
Expand All @@ -19,6 +30,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 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
Expand Down Expand Up @@ -104,14 +121,16 @@ target_include_directories( gsl INTERFACE ${GSL_LITE_INCLUDE_DIR} )
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})
add_dependencies(${LIB_NAME} gsl)
target_link_libraries(${LIB_NAME} PRIVATE gsl OpenSSL::Crypto)
target_include_directories(${LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

Expand Down
4 changes: 4 additions & 0 deletions cmake/namespace.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

// Configurable top-level namespace
#define SFRAME_NAMESPACE @SFRAME_CXX_NAMESPACE@
5 changes: 3 additions & 2 deletions include/sframe/sframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <memory>
#include <vector>

#include <namespace.h>
#include <gsl/gsl-lite.hpp>

namespace sframe {
namespace SFRAME_NAMESPACE {

struct openssl_error : std::runtime_error
{
Expand Down Expand Up @@ -147,4 +148,4 @@ class MLSContext : public SFrame
KeyState& get_state(KeyID key_id) override;
};

} // namespace sframe
} // namespace SFRAME_NAMESPACE
4 changes: 2 additions & 2 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "crypto.h"

namespace sframe {
namespace SFRAME_NAMESPACE {

///
/// Information about algorithms
Expand Down Expand Up @@ -91,4 +91,4 @@ cipher_overhead(CipherSuite suite)
}
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE
4 changes: 2 additions & 2 deletions src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <array>

namespace sframe {
namespace SFRAME_NAMESPACE {

///
/// Information about algorithms
Expand Down Expand Up @@ -54,4 +54,4 @@ open(CipherSuite suite,
input_bytes aad,
input_bytes ct);

} // namespace sframe
} // namespace SFRAME_NAMESPACE
4 changes: 2 additions & 2 deletions src/crypto_boringssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <openssl/hmac.h>
#include <openssl/mem.h>

namespace sframe {
namespace SFRAME_NAMESPACE {

///
/// Convert between native identifiers / errors and OpenSSL ones
Expand Down Expand Up @@ -409,6 +409,6 @@ open(CipherSuite suite,
throw unsupported_ciphersuite_error();
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE

#endif // defined(OPENSSL_3)
4 changes: 2 additions & 2 deletions src/crypto_openssl11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <openssl/err.h>
#include <openssl/evp.h>

namespace sframe {
namespace SFRAME_NAMESPACE {

///
/// Scoped pointers for OpenSSL objects
Expand Down Expand Up @@ -468,6 +468,6 @@ open(CipherSuite suite,
throw unsupported_ciphersuite_error();
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE

#endif // defined(OPENSSL_1_1)
4 changes: 2 additions & 2 deletions src/crypto_openssl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <openssl/kdf.h>
#include <openssl/params.h>

namespace sframe {
namespace SFRAME_NAMESPACE {

///
/// Convert between native identifiers / errors and OpenSSL ones
Expand Down Expand Up @@ -448,6 +448,6 @@ open(CipherSuite suite,
throw unsupported_ciphersuite_error();
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE

#endif // defined(OPENSSL_3)
4 changes: 2 additions & 2 deletions src/header.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "header.h"

namespace sframe {
namespace SFRAME_NAMESPACE {

static size_t
uint_size(uint64_t val)
Expand Down Expand Up @@ -109,4 +109,4 @@ Header::encode(output_bytes buffer) const
return 1 + kid_size + ctr_size;
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE
4 changes: 2 additions & 2 deletions src/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <sframe/sframe.h>

namespace sframe {
namespace SFRAME_NAMESPACE {

void
encode_uint(uint64_t val, output_bytes buffer);
Expand All @@ -21,4 +21,4 @@ struct Header
static constexpr size_t max_size = 1 + 7 + 7;
};

} // namespace sframe
} // namespace SFRAME_NAMESPACE
4 changes: 2 additions & 2 deletions src/sframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdexcept>
#include <tuple>

namespace sframe {
namespace SFRAME_NAMESPACE {

std::ostream&
operator<<(std::ostream& str, const input_bytes data)
Expand Down Expand Up @@ -294,4 +294,4 @@ MLSContext::get_state(KeyID key_id)
return epoch->get(suite, sender_id);
}

} // namespace sframe
} // namespace SFRAME_NAMESPACE
2 changes: 1 addition & 1 deletion test/sframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdexcept> // for invalid_argument
#include <string> // for basic_string, operator==

using namespace sframe;
using namespace SFRAME_NAMESPACE;

static bytes
from_hex(const std::string& hex)
Expand Down