Skip to content

Small fixes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Language: Cpp
BasedOnStyle: Google
ColumnLimit: 80
IndentWidth: 2
Standard: Cpp11
Standard: c++17
47 changes: 47 additions & 0 deletions .dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM ubuntu:24.04

# Define Conan and CMake versions
ARG CONAN_VERSION=2.6.0
ARG CMAKE_VERSION=3.30.1

# Define User ID and Group ID
ARG USER_ID=1000
ARG GROUP_ID=1000

WORKDIR /project

# Define Labels
LABEL maintainer="Michele Adduci <adduci@tutanota.com>" \
description="Docker image for C++ development with Conan and CMake" \
cmake.version="${CMAKE_VERSION}" \
conan.version="${CONAN_VERSION}"

# Install basic tooling
RUN apt-get update && \
apt-get install -y \
build-essential \
curl \
gcc \
cppcheck \
clang-format && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Conan and CMake from GitHub Releases
RUN curl -fsSL https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-amd64.deb -o /tmp/conan.deb && \
dpkg -i /tmp/conan.deb && \
curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz -o /tmp/cmake.tar.gz && \
mkdir -p /opt/cmake && \
tar -xzf /tmp/cmake.tar.gz -C /opt/cmake/ --strip-components=1 && \
chmod +x /opt/cmake/bin/* && \
ln -sf /opt/cmake/bin/cmake /usr/bin/cmake && \
ln -sf /opt/cmake/bin/ctest /usr/bin/ctest && \
ln -sf /opt/cmake/bin/cpack /usr/bin/cpack && \
ln -sf /opt/cmake/bin/ccmake /usr/bin/ccmake && \
rm -rf /tmp/*

# Create non-root user to run container with less privileges
USER ${USER_ID}

# Run Conan profile detection as non-root user
RUN conan profile detect
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ project(moderncpp-project LANGUAGES CXX DESCRIPTION "moderncpp-project is a star

# Set Project version (used for library versioning and for CPack)
set(CMAKE_PROJECT_VERSION_MAJOR 1)
set(CMAKE_PROJECT_VERSION_MINOR 0)
set(CMAKE_PROJECT_VERSION_PATCH 0)
set(CMAKE_PROJECT_VERSION_MINOR 1)
set(CMAKE_PROJECT_VERSION_PATCH 2)
set(CMAKE_PROJECT_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})

# Set required C++ Standard
Expand Down
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[requires]
openssl/3.2.1
openssl/3.2.2
doctest/2.4.11

[generators]
Expand Down
11 changes: 6 additions & 5 deletions project/hellolib/src/hellolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ int32_t hellolib::saySomethingHashed(
return 1;
}

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

if(1 != EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
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())) {
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(1 != EVP_DigestFinal_ex(context, buffer.data(), NULL)) {
if (1 != EVP_DigestFinal_ex(context, buffer.data(), NULL)) {
std::cerr << "Failed to finalize hash result\n";
return 5;
}
Expand Down