From 3692eaccdd4e79aa1133ba3addc6d26bebbe8672 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Thu, 12 Jan 2023 06:36:52 +0200 Subject: [PATCH] Remove ubuntu 18.04 and cleanup code (#517) IB-7398 Signed-off-by: Raul Metsma Signed-off-by: Raul Metsma --- .github/workflows/build.yml | 14 ++--- CMakeLists.txt | 23 +------- src/CMakeLists.txt | 12 ++--- src/DataFile.cpp | 10 ++-- src/DataFile_p.h | 20 ++++--- src/digidoc-tool.cpp | 16 ++---- src/util/File.cpp | 101 ++++-------------------------------- src/util/File.h | 3 -- 8 files changed, 34 insertions(+), 165 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b0d64815..700c29250 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -106,24 +106,18 @@ jobs: container: ${{ matrix.container }} strategy: matrix: - container: ['ubuntu:18.04', 'ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:22.10'] + container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:22.10'] env: DEBIAN_FRONTEND: noninteractive DEBFULLNAME: github-actions DEBEMAIL: github-actions@github.com steps: + - name: Install dependencies + run: apt update -qq && apt install --no-install-recommends -y git lsb-release fakeroot build-essential devscripts cdbs cmake xxd xsdcxx libxml-security-c-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 with: submodules: recursive - - name: Add open-eid repo - if: matrix.container == 'ubuntu:18.04' - run: | - apt update -qq && apt install --no-install-recommends -y curl ca-certificates gnupg2 lsb-release - curl https://installer.id.ee/media/install-scripts/C6C83D68.pub | gpg --dearmor | tee /etc/apt/trusted.gpg.d/ria-repository.gpg > /dev/null - echo "deb https://installer.id.ee/media/ubuntu/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ria-repository.list - - name: Install dependencies - run: apt update -qq && apt install --no-install-recommends -y lsb-release fakeroot build-essential devscripts cdbs cmake xxd xsdcxx libxml-security-c-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian - name: Setup changelog run: | export VERSION=$(grep project CMakeLists.txt | egrep -o "([0-9]{1,}\.)+[0-9]{1,}") diff --git a/CMakeLists.txt b/CMakeLists.txt index 834e2b808..770711c67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,5 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(libdigidocpp VERSION 3.15.0) -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() -if(POLICY CMP0078) - cmake_policy(SET CMP0078 NEW) -endif() -if(POLICY CMP0086) - cmake_policy(SET CMP0086 NEW) -endif() set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) include(VersionInfo) @@ -61,18 +52,6 @@ find_package(SWIG) find_package(JNI) find_package(Python3 COMPONENTS Interpreter Development) -if(Python3_FOUND) - add_library(PythonModule INTERFACE) - target_link_libraries(PythonModule INTERFACE Python3::Module) -else() - find_package(PythonLibs) - if(PYTHONLIBS_FOUND) - add_library(PythonModule INTERFACE) - target_include_directories(PythonModule INTERFACE ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(PythonModule INTERFACE ${PYTHON_LIBRARIES}) - endif() -endif() - if( DOXYGEN_FOUND ) configure_file( ${CMAKE_SOURCE_DIR}/etc/Doxyfile.in Doxyfile @ONLY ) add_custom_target( docs ALL diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d01b1dcb..f5a75a5ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -245,9 +245,7 @@ target_link_libraries(digidocpp PRIVATE ${CMAKE_DL_LIBS} minizip digidocpp_priv) if( BUILD_TOOLS ) add_executable(digidoc-tool digidoc-tool.rc digidoc-tool.cpp) - target_link_libraries(digidoc-tool digidocpp digidocpp_priv Threads::Threads - "$<$,$,9.0>>:-lstdc++fs>" - ) + target_link_libraries(digidoc-tool digidocpp digidocpp_priv Threads::Threads) configure_file( digidoc-tool.1.cmake digidoc-tool.1 ) endif() @@ -288,11 +286,11 @@ if(SWIG_FOUND) target_link_libraries(digidoc_java Iconv::Iconv) endif() endif() - if(TARGET PythonModule) + if(Python3_FOUND) set(CMAKE_SWIG_FLAGS -py3) set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) swig_add_library(digidoc_python TYPE SHARED LANGUAGE python SOURCES ../libdigidocpp.i) - target_link_libraries(${SWIG_MODULE_digidoc_python_REAL_NAME} digidocpp digidocpp_util PythonModule) + target_link_libraries(digidoc_python digidocpp digidocpp_util Python3::Module) #configure_file(setup.py.cmake setup.py) #install(CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") if(NOT Python3_SITELIB) @@ -304,9 +302,9 @@ if(SWIG_FOUND) set(Python3_SITELIB ${CMAKE_INSTALL_BINDIR}) install(FILES $ DESTINATION ${Python3_SITELIB} OPTIONAL) else() - set_target_properties(${SWIG_MODULE_digidoc_python_REAL_NAME} PROPERTIES SUFFIX .so) + set_target_properties(digidoc_python PROPERTIES SUFFIX .so) endif() - install(TARGETS ${SWIG_MODULE_digidoc_python_REAL_NAME} DESTINATION ${Python3_SITELIB}) + install(TARGETS digidoc_python DESTINATION ${Python3_SITELIB}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc.py DESTINATION ${Python3_SITELIB}) endif() if(WIN32) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index f12066261..6393f6059 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -23,6 +23,7 @@ #include "util/File.h" #include "util/log.h" +#include #include using namespace digidoc; @@ -86,13 +87,11 @@ DataFile::DataFile() = default; DataFile::~DataFile() = default; -DataFilePrivate::DataFilePrivate(unique_ptr is, string filename, string mediatype, - string id, vector digestValue) +DataFilePrivate::DataFilePrivate(unique_ptr &&is, string filename, string mediatype, string id) : m_is(move(is)) , m_id(move(id)) , m_filename(move(filename)) , m_mediatype(move(mediatype)) - , m_digestValue(move(digestValue)) { m_is->seekg(0, istream::end); istream::pos_type pos = m_is->tellg(); @@ -101,8 +100,6 @@ DataFilePrivate::DataFilePrivate(unique_ptr is, string filename, string vector DataFilePrivate::calcDigest(const string &method) const { - if(!m_digestValue.empty()) - return m_digestValue; Digest calc(method); calcDigest(&calc); return calc.result(); @@ -110,7 +107,7 @@ vector DataFilePrivate::calcDigest(const string &method) const void DataFilePrivate::calcDigest(Digest *digest) const { - vector buf(10240, 0); + array buf{}; m_is->clear(); m_is->seekg(0); while(*m_is) @@ -125,7 +122,6 @@ void DataFilePrivate::saveAs(const string& path) const { ofstream ofs(File::encodeName(path).c_str(), ofstream::binary); saveAs(ofs); - ofs.close(); } void DataFilePrivate::saveAs(ostream &os) const diff --git a/src/DataFile_p.h b/src/DataFile_p.h index f20dbd021..d03e9a295 100644 --- a/src/DataFile_p.h +++ b/src/DataFile_p.h @@ -28,25 +28,23 @@ namespace digidoc { class Digest; -class DataFilePrivate: public DataFile +class DataFilePrivate final: public DataFile { public: - DataFilePrivate(std::unique_ptr is, std::string filename, std::string mediatype, std::string id = {}, - std::vector digestValue = {}); + DataFilePrivate(std::unique_ptr &&is, std::string filename, std::string mediatype, std::string id = {}); - std::string id() const override { return m_id.empty() ? m_filename : m_id; } - std::string fileName() const override { return m_filename; } - unsigned long fileSize() const override { return m_size; } - std::string mediaType() const override { return m_mediatype; } + std::string id() const final { return m_id.empty() ? m_filename : m_id; } + std::string fileName() const final { return m_filename; } + unsigned long fileSize() const final { return m_size; } + std::string mediaType() const final { return m_mediatype; } - std::vector calcDigest(const std::string &method) const override; + std::vector calcDigest(const std::string &method) const final; void calcDigest(Digest *method) const; - void saveAs(std::ostream &os) const override; - void saveAs(const std::string& path) const override; + void saveAs(std::ostream &os) const final; + void saveAs(const std::string& path) const final; std::unique_ptr m_is; std::string m_id, m_filename, m_mediatype; - std::vector m_digestValue; unsigned long m_size; }; } diff --git a/src/digidoc-tool.cpp b/src/digidoc-tool.cpp index 3862b70aa..a841e6da0 100644 --- a/src/digidoc-tool.cpp +++ b/src/digidoc-tool.cpp @@ -32,11 +32,8 @@ #include "util/log.h" #include -#include -#include -#include +#include #include -#include #include #include @@ -51,13 +48,7 @@ using namespace digidoc; using namespace digidoc::util; using namespace std; -#if __has_include() -#include -namespace fs = std::filesystem; -#else -#include -namespace fs = std::experimental::filesystem; -#endif +namespace fs = filesystem; namespace std { @@ -490,9 +481,8 @@ unique_ptr ToolConfig::getSigner(bool getwebsigner) const win->setThumbprint(thumbprint); signer = unique_ptr(win.release()); } - else #endif - if(!pkcs12.empty()) + else if(!pkcs12.empty()) signer = make_unique(pkcs12, pin); else signer = make_unique(pkcs11, pin); diff --git a/src/util/File.cpp b/src/util/File.cpp index 1ce175510..d85ce1584 100644 --- a/src/util/File.cpp +++ b/src/util/File.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ using namespace digidoc; using namespace digidoc::util; using namespace std; +namespace fs = filesystem; #ifdef _WIN32 #define f_stat _wstat64 @@ -58,77 +60,6 @@ using f_statbuf = struct stat; using f_utimbuf = struct utimbuf; #endif -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) -#include -#include -#include -#include -#include - -/** - * Helper method for converting from non-UTF-8 encoded strings to UTF-8. - * Supported LANG values for Linux: see /usr/share/i18n/SUPPORTED. - * Supported encodings for libiconv: see iconv --list . - * - * Note! If non-ASCII characters are used we assume a proper LANG value!!! - * - * @param str_in The string to be converted. - * @return Returns the input string in UTF-8. - */ -string File::convertUTF8(string_view str_in, bool to_UTF) -{ - string charset = nl_langinfo(CODESET); - // no conversion needed for UTF-8 - if(charset == "UTF-8" || charset == "utf-8") - return string(str_in); - - iconv_t ic_descr = iconv_t(-1); - try - { - ic_descr = to_UTF ? iconv_open("UTF-8", charset.c_str()) : iconv_open(charset.c_str(), "UTF-8"); - } - catch(exception &) {} - - if(ic_descr == iconv_t(-1)) - return string(str_in); - - char* inptr = (char*)str_in.data(); - size_t inleft = str_in.size(); - - string out; - char outbuf[64]; - char* outptr; - size_t outleft; - - while(inleft > 0) - { - outbuf[0] = '\0'; - outptr = (char *)outbuf; - outleft = sizeof(outbuf) - sizeof(outbuf[0]); - - size_t result = iconv(ic_descr, &inptr, &inleft, &outptr, &outleft); - if(result == size_t(-1)) - { - switch(errno) - { - case E2BIG: break; - case EILSEQ: - case EINVAL: - default: - iconv_close(ic_descr); - return string(str_in); - break; - } - } - *outptr = '\0'; - out += outbuf; - } - iconv_close(ic_descr); - - return out; -} -#endif - stack File::tempFiles; string File::confPath() @@ -167,23 +98,15 @@ File::f_string File::encodeName(string_view fileName) { if(fileName.empty()) return {}; -#if defined(_WIN32) - int len = MultiByteToWideChar(CP_UTF8, 0, fileName.data(), int(fileName.size()), nullptr, 0); - f_string out(size_t(len), 0); - len = MultiByteToWideChar(CP_UTF8, 0, fileName.data(), int(fileName.size()), out.data(), len); -#elif defined(__APPLE__) - CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0); - CFStringAppendCString(ref, fileName.data(), kCFStringEncodingUTF8); - CFStringNormalize(ref, kCFStringNormalizationFormD); - +#ifdef __APPLE__ + CFStringRef ref = CFStringCreateWithBytesNoCopy({}, (UInt8 *)fileName.data(), + CFIndex(fileName.size()), kCFStringEncodingUTF8, FALSE, kCFAllocatorNull); string out(fileName.size() * 2, 0); - CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8); + CFStringGetFileSystemRepresentation(ref, out.data(), CFIndex(out.size())); CFRelease(ref); out.resize(strlen(out.c_str())); -#elif defined(__ANDROID__) - f_string out = string(fileName); #else - f_string out = convertUTF8(fileName,false); + f_string out = fs::u8path(fileName); #endif return out; } @@ -197,11 +120,7 @@ string File::decodeName(const f_string_view &localFileName) { if(localFileName.empty()) return {}; -#if defined(_WIN32) - int len = WideCharToMultiByte(CP_UTF8, 0, localFileName.data(), int(localFileName.size()), nullptr, 0, nullptr, nullptr); - string out(size_t(len), 0); - WideCharToMultiByte(CP_UTF8, 0, localFileName.data(), int(localFileName.size()), out.data(), len, nullptr, nullptr); -#elif defined(__APPLE__) +#ifdef __APPLE__ CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0); CFStringAppendCString(ref, localFileName.data(), kCFStringEncodingUTF8); CFStringNormalize(ref, kCFStringNormalizationFormC); @@ -210,10 +129,8 @@ string File::decodeName(const f_string_view &localFileName) CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8); CFRelease(ref); out.resize(strlen(out.c_str())); -#elif defined(__ANDROID__) - string out = string(localFileName); #else - string out = convertUTF8(localFileName,true); + string out = fs::path(localFileName).u8string(); #endif return out; } diff --git a/src/util/File.h b/src/util/File.h index 41bbaeab6..683114a90 100644 --- a/src/util/File.h +++ b/src/util/File.h @@ -71,9 +71,6 @@ namespace digidoc #endif private: -#if !defined(_WIN32) && !defined(__APPLE__) - static std::string convertUTF8(std::string_view str_in, bool to_UTF); -#endif static std::stack tempFiles; };