Add base64 decoding function
This commit is contained in:
parent
6b9502ea3e
commit
eeab1d5c5e
6 changed files with 52 additions and 1 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -7,3 +7,6 @@
|
||||||
[submodule "subprojects/SQLiteCpp/SQLiteCpp"]
|
[submodule "subprojects/SQLiteCpp/SQLiteCpp"]
|
||||||
path = subprojects/SQLiteCpp/SQLiteCpp
|
path = subprojects/SQLiteCpp/SQLiteCpp
|
||||||
url = https://github.com/SRombauts/SQLiteCpp.git
|
url = https://github.com/SRombauts/SQLiteCpp.git
|
||||||
|
[submodule "src/gnulib"]
|
||||||
|
path = src/gnulib
|
||||||
|
url = git://git.savannah.gnu.org/gnulib.git
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
project('orotool', 'cpp',
|
project('orotool', 'cpp', 'c',
|
||||||
version: '0.1.0',
|
version: '0.1.0',
|
||||||
meson_version: '>=0.49.2',
|
meson_version: '>=0.49.2',
|
||||||
default_options: ['buildtype=debug', 'cpp_std=gnu++17'],
|
default_options: ['buildtype=debug', 'cpp_std=gnu++17'],
|
||||||
|
|
1
src/gnulib
Submodule
1
src/gnulib
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 444acd314f6c4a1fb7ea7412a54b8ea5fc0ad7c2
|
|
@ -27,6 +27,10 @@ project_config_file = configure_file(
|
||||||
configuration: conf,
|
configuration: conf,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gnulib_conf = configuration_data()
|
||||||
|
gnulib_conf.set('_GL_ATTRIBUTE_CONST', '__attribute__ ((__const__))')
|
||||||
|
configure_file(output : 'config.h', configuration : gnulib_conf)
|
||||||
|
|
||||||
lib_deps = [
|
lib_deps = [
|
||||||
restc_cpp_dep,
|
restc_cpp_dep,
|
||||||
sqlitecpp_dep,
|
sqlitecpp_dep,
|
||||||
|
@ -47,6 +51,8 @@ executable(meson.project_name(),
|
||||||
'timer_items.cpp',
|
'timer_items.cpp',
|
||||||
'timer_icons.cpp',
|
'timer_icons.cpp',
|
||||||
'oro/originsdb.cpp',
|
'oro/originsdb.cpp',
|
||||||
|
'gnulib/lib/base64.c',
|
||||||
|
'oro/base64.cpp',
|
||||||
project_config_file,
|
project_config_file,
|
||||||
install: true,
|
install: true,
|
||||||
dependencies: lib_deps,
|
dependencies: lib_deps,
|
||||||
|
|
31
src/oro/base64.cpp
Normal file
31
src/oro/base64.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "base64.hpp"
|
||||||
|
#include <config.h>
|
||||||
|
#define restrict __restrict__
|
||||||
|
#include "gnulib/lib/base64.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#if defined(base64_decode)
|
||||||
|
# undef base64_decode
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace oro {
|
||||||
|
|
||||||
|
std::vector<char> base64_decode (std::string_view text) {
|
||||||
|
base64_decode_context ctx;
|
||||||
|
base64_decode_ctx_init(&ctx);
|
||||||
|
std::vector<char> retval(3 * (text.size() / 4) + 3);
|
||||||
|
|
||||||
|
size_t out_size = retval.size();
|
||||||
|
const bool success = base64_decode_ctx(&ctx, text.data(), text.size(), retval.data(), &out_size);
|
||||||
|
if (not success)
|
||||||
|
throw std::runtime_error("Base64 decode failed");
|
||||||
|
|
||||||
|
assert(out_size <= retval.size());
|
||||||
|
retval.resize(out_size);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace oro
|
||||||
|
|
||||||
|
#undef restrict
|
10
src/oro/base64.hpp
Normal file
10
src/oro/base64.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace oro {
|
||||||
|
|
||||||
|
std::vector<char> base64_decode (std::string_view text);
|
||||||
|
|
||||||
|
} //namespace oro
|
Loading…
Add table
Reference in a new issue