Skip to content
Snippets Groups Projects
Verified Commit da70ea2c authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: base64

parent 7b722701
No related branches found
No related tags found
No related merge requests found
Pipeline #9553 failed
...@@ -41,24 +41,24 @@ conan_basic_setup() ...@@ -41,24 +41,24 @@ conan_basic_setup()
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include") set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
find_program(iwyu NAMES include-what-you-use iwyu PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin) #find_program(iwyu NAMES include-what-you-use iwyu PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin)
if(NOT iwyu) #if(NOT iwyu)
message(STATUS "include-what-you-use: Not found") #message(STATUS "include-what-you-use: Not found")
else() #else()
message(STATUS "include-what-you-use: ${iwyu}") #message(STATUS "include-what-you-use: ${iwyu}")
set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu}) #set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu})
endif() #endif()
find_program(clang_tidy NAMES clang-tidy clang-tidy-11) #find_program(clang_tidy NAMES clang-tidy clang-tidy-11)
if(NOT clang_tidy) #if(NOT clang_tidy)
message(STATUS "clang-tidy: Not found") #message(STATUS "clang-tidy: Not found")
else() #else()
message(STATUS "clang-tidy: ${clang_tidy}") #message(STATUS "clang-tidy: ${clang_tidy}")
set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" #set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
"--header-filter=caosdb/.*[^\(\.pb\.h\)]$" #"--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
"--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*" #"--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
"--warnings-as-errors=*") #"--warnings-as-errors=*")
endif() #endif()
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(include) add_subdirectory(include)
...@@ -138,6 +138,7 @@ target_include_directories(caosdb_info_v1alpha1 PUBLIC ...@@ -138,6 +138,7 @@ target_include_directories(caosdb_info_v1alpha1 PUBLIC
target_link_libraries(caosdb target_link_libraries(caosdb
caosdb_info_v1alpha1 caosdb_info_v1alpha1
${CONAN_LIBS}
${_REFLECTION} ${_REFLECTION}
${_GRPC_GRPCPP} ${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}) ${_PROTOBUF_LIBPROTOBUF})
......
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
#ifndef CAOSDB_UTILS_H #ifndef CAOSDB_UTILS_H
#define CAOSDB_UTILS_H #define CAOSDB_UTILS_H
#include <iostream>
#include <string_view> #include <string_view>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#include <boost/beast/core/detail/base64.hpp>
namespace caosdb::utils { namespace caosdb::utils {
...@@ -63,11 +65,17 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back) ...@@ -63,11 +65,17 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back)
} }
/** /**
* @brief * @brief Encode string as base64
* @todo use boost-beast's implementation
*/ */
inline auto base64_encode(const std::string &plain) -> std::string { inline auto base64_encode(const std::string &plain) -> std::string {
return plain; auto size_plain = plain.size();
auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain);
char encoded[size_encoded];
boost::beast::detail::base64::encode(&encoded, plain.c_str(), size_plain);
// the encoded char[] is not null terminated, so explicitely set the length
return std::string(encoded, encoded + size_encoded);
} }
} // namespace caosdb::utils } // namespace caosdb::utils
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
# append all the test cases here (file name without the ".cpp" suffix) # append all the test cases here (file name without the ".cpp" suffix)
set(test_cases set(test_cases
test_connection test_connection
test_utils
) )
# download gtest library # download gtest library
......
/*
*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "caosdb/utils.h"
#include <string>
#include <gtest/gtest-message.h>
#include <gtest/gtest-test-part.h>
#include "gtest/gtest_pred_impl.h"
TEST(test_utils, base64_encode) {
auto test_plain = std::string("Test");
auto test_encoded = std::string("VGVzdA==");
ASSERT_EQ(4, test_plain.size());
ASSERT_EQ(8, boost::beast::detail::base64::encoded_size(test_plain.size()));
ASSERT_EQ(test_encoded, caosdb::utils::base64_encode(test_plain));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment