Skip to content

Commit 917511e

Browse files
authored
Merge pull request #58 from cisco/crypto-provider
Refactor for crypto library agility
2 parents c79c927 + 715c8ea commit 917511e

File tree

9 files changed

+1003
-486
lines changed

9 files changed

+1003
-486
lines changed

CMakeLists.txt

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.10)
22

33
project(sframe
44
VERSION 0.1
@@ -9,6 +9,11 @@ option(TESTING "Build tests" OFF)
99
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
1010
option(SANITIZERS "Enable sanitizers" OFF)
1111

12+
# Use -DCRYPTO=(OPENSSL_1_1 | OPENSSL_3) to configure crypto
13+
if(NOT DEFINED CRYPTO)
14+
set(CRYPTO "OPENSSL_3")
15+
endif()
16+
1217
###
1318
### Global Config
1419
###
@@ -49,7 +54,20 @@ endif()
4954
###
5055

5156
# External libraries
52-
find_package(OpenSSL 1.1 REQUIRED)
57+
if(${CRYPTO} STREQUAL "OPENSSL_1_1")
58+
message(STATUS "Configuring with OpenSSL 1.1")
59+
find_package(OpenSSL 1.1 EXACT REQUIRED)
60+
add_compile_definitions(OPENSSL_1_1)
61+
set(CRYPTO_LIB OpenSSL::Crypto)
62+
elseif(${CRYPTO} STREQUAL "OPENSSL_3")
63+
message(STATUS "Configuring with OpenSSL 3")
64+
find_package(OpenSSL 3 EXACT REQUIRED)
65+
add_compile_definitions(OPENSSL_3)
66+
set(CRYPTO_LIB OpenSSL::Crypto)
67+
else()
68+
message(FATAL_ERROR "Please select a crypto back-end (OPENSSL_1_1 or OPENSSL_3) [${CRYPTO}]")
69+
endif()
70+
5371

5472
###
5573
### Library Config
@@ -61,7 +79,7 @@ file(GLOB_RECURSE LIB_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/inc
6179
file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
6280

6381
add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_SOURCES})
64-
target_link_libraries(${LIB_NAME} PRIVATE OpenSSL::Crypto)
82+
target_link_libraries(${LIB_NAME} PRIVATE ${CRYPTO_LIB})
6583
target_include_directories(${LIB_NAME}
6684
PUBLIC
6785
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>

include/sframe/sframe.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace sframe {
77

8-
struct openssl_error : std::runtime_error
8+
struct crypto_error : std::runtime_error
99
{
10-
openssl_error();
10+
crypto_error();
1111
};
1212

1313
struct unsupported_ciphersuite_error : std::runtime_error
@@ -64,9 +64,9 @@ class vector
6464
}
6565

6666
constexpr vector(size_t size)
67-
: _size(size)
6867
{
6968
std::fill(_data.begin(), _data.end(), T());
69+
resize(size);
7070
}
7171

7272
constexpr vector(std::initializer_list<uint8_t> content)
@@ -99,6 +99,7 @@ class vector
9999
auto end() { return _data.begin() + _size; }
100100

101101
auto size() const { return _size; }
102+
auto capacity() const { return N; }
102103
void resize(size_t size)
103104
{
104105
if (size > N) {

0 commit comments

Comments
 (0)