Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
da70ea2c
Verified
Commit
da70ea2c
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: base64
parent
7b722701
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#9553
failed
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Changes
4
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CMakeLists.txt
+19
-18
19 additions, 18 deletions
CMakeLists.txt
include/caosdb/utils.h
+11
-3
11 additions, 3 deletions
include/caosdb/utils.h
test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/CMakeLists.txt
test/test_utils.cpp
+35
-0
35 additions, 0 deletions
test/test_utils.cpp
with
66 additions
and
21 deletions
CMakeLists.txt
+
19
−
18
View file @
da70ea2c
...
...
@@ -41,24 +41,24 @@ conan_basic_setup()
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
)
if
(
NOT iwyu
)
message
(
STATUS
"include-what-you-use: Not found"
)
else
()
message
(
STATUS
"include-what-you-use:
${
iwyu
}
"
)
set
(
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${
iwyu
}
)
endif
()
find_program
(
clang_tidy NAMES clang-tidy clang-tidy-11
)
if
(
NOT clang_tidy
)
message
(
STATUS
"clang-tidy: Not found"
)
else
()
message
(
STATUS
"clang-tidy:
${
clang_tidy
}
"
)
set
(
_CMAKE_CXX_CLANG_TIDY
"
${
clang_tidy
}
"
"--header-filter=caosdb/.*[^
\(
\.pb\.h
\)
]$"
"--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
"--warnings-as-errors=*"
)
endif
()
#
find_program(iwyu NAMES include-what-you-use iwyu PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin)
#
if(NOT iwyu)
#
message(STATUS "include-what-you-use: Not found")
#
else()
#
message(STATUS "include-what-you-use: ${iwyu}")
#
set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu})
#
endif()
#
find_program(clang_tidy NAMES clang-tidy clang-tidy-11)
#
if(NOT clang_tidy)
#
message(STATUS "clang-tidy: Not found")
#
else()
#
message(STATUS "clang-tidy: ${clang_tidy}")
#
set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
#
"--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
#
"--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
#
"--warnings-as-errors=*")
#
endif()
add_subdirectory
(
src
)
add_subdirectory
(
include
)
...
...
@@ -138,6 +138,7 @@ target_include_directories(caosdb_info_v1alpha1 PUBLIC
target_link_libraries
(
caosdb
caosdb_info_v1alpha1
${
CONAN_LIBS
}
${
_REFLECTION
}
${
_GRPC_GRPCPP
}
${
_PROTOBUF_LIBPROTOBUF
}
)
...
...
This diff is collapsed.
Click to expand it.
include/caosdb/utils.h
+
11
−
3
View file @
da70ea2c
...
...
@@ -21,10 +21,12 @@
#ifndef CAOSDB_UTILS_H
#define CAOSDB_UTILS_H
#include
<iostream>
#include
<string_view>
#include
<fstream>
#include
<string>
#include
<cstdlib>
#include
<boost/beast/core/detail/base64.hpp>
namespace
caosdb
::
utils
{
...
...
@@ -63,11 +65,17 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back)
}
/**
* @brief
* @todo use boost-beast's implementation
* @brief Encode string as base64
*/
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
...
...
This diff is collapsed.
Click to expand it.
test/CMakeLists.txt
+
1
−
0
View file @
da70ea2c
...
...
@@ -21,6 +21,7 @@
# append all the test cases here (file name without the ".cpp" suffix)
set
(
test_cases
test_connection
test_utils
)
# download gtest library
...
...
This diff is collapsed.
Click to expand it.
test/test_utils.cpp
0 → 100644
+
35
−
0
View file @
da70ea2c
/*
*
* 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
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment