Skip to content

Commit

Permalink
Conan v2 (#7)
Browse files Browse the repository at this point in the history
Updated to Conan V2 usage

Upgraded OpenSSL to 3.x

Upgraded Doctest to 2.4.11
  • Loading branch information
madduci authored Jun 24, 2023
1 parent d9f108c commit 3e567bd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

Expand All @@ -20,38 +20,38 @@ jobs:

steps:
- name: Perform checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install Python environment
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install conan
run: |
pip install conan --upgrade
conan profile new default --detect
conan profile detect --force
- name: Linux build
if: matrix.os == 'ubuntu-20.04'
run: |
conan profile update settings.compiler.libcxx=libstdc++11 default
mkdir -p build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
- name: Mac build
if: matrix.os == 'macos-latest'
run: |
conan profile update settings.compiler.libcxx=libc++ default
mkdir -p build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
- name: Windows build
if: matrix.os == 'windows-latest'
run: |
md build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
18 changes: 9 additions & 9 deletions .github/workflows/build-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

Expand All @@ -20,38 +20,38 @@ jobs:

steps:
- name: Perform checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install Python environment
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install conan
run: |
pip install conan --upgrade
conan profile new default --detect
conan profile detect --force
- name: Linux build
if: matrix.os == 'ubuntu-20.04'
run: |
conan profile update settings.compiler.libcxx=libstdc++11 default
mkdir -p build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
- name: Mac build
if: matrix.os == 'macos-latest'
run: |
conan profile update settings.compiler.libcxx=libc++ default
mkdir -p build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
- name: Windows build
if: matrix.os == 'windows-latest'
run: |
md build && cd build
conan install .. --build=missing
conan install .. --output-folder=. --build=missing
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
*.pyc
.vscode
CMakeUserPresets.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This repository aims to represent a template for Modern C++ projects, including
## Requirements

* a modern C++17 compiler (`gcc-8`, `clang-6.0`, `MSVC 2017` or above)
* [`cmake`](https://cmake.org) 3.10+
* [`conan`](https://conan.io) 1.28+ (optional)
* [`cmake`](https://cmake.org) 3.15+
* [`conan`](https://conan.io) 2.0+ (optional)
* `cppcheck` (optional)
* `clang-format` (optional)

Expand Down Expand Up @@ -62,8 +62,8 @@ The project can be built using the following commands:
cd /path/to/this/project
mkdir -p build # md build (on Windows)
cd build
conan install ..
cmake -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE ..
conan install .. --output-folder=. --build=missing
cmake -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
cmake --build . --target format
cmake --build . --target package
Expand Down
8 changes: 4 additions & 4 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[requires]
openssl/1.1.1s
doctest/2.4.9
openssl/3.1.1
doctest/2.4.11

[generators]
cmake_find_package
CMakeDeps

[options]
openssl:shared=False
pkg/openssl:shared=False
22 changes: 13 additions & 9 deletions project/hellolib/src/hellolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>

#ifdef WITH_OPENSSL
#include <openssl/sha.h>
#include <openssl/evp.h>

#include <array>
#include <iomanip>
Expand All @@ -30,22 +30,26 @@ int32_t hellolib::saySomethingHashed(
return 1;
}

SHA256_CTX context;
if (!SHA256_Init(&context)) {
std::cerr << "Failed to initialize context\n";
EVP_MD_CTX *context = EVP_MD_CTX_new();
if(context == NULL) {
std::cerr << "Failed to create context\n";
return 2;
}

if (!SHA256_Update(&context, (unsigned char *)something.c_str(),
something.size())) {
std::cerr << "Failed to create hash value\n";
if(1 != EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
std::cerr << "Failed to initialize context\n";
return 3;
}

if(1 != EVP_DigestUpdate(context, (unsigned char *)something.c_str(), something.size())) {
std::cerr << "Failed to create hash value\n";
return 4;
}

std::array<unsigned char, 32> buffer{};
if (!SHA256_Final(buffer.data(), &context)) {
if(1 != EVP_DigestFinal_ex(context, buffer.data(), NULL)) {
std::cerr << "Failed to finalize hash result\n";
return 4;
return 5;
}

// Transform byte-array to string
Expand Down

0 comments on commit 3e567bd

Please sign in to comment.