Skip to content

Commit 83fa7eb

Browse files
committed
Remove ubuntu 18.04 and cleanup code
IB-7398 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 77d7793 commit 83fa7eb

8 files changed

Lines changed: 34 additions & 165 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,18 @@ jobs:
106106
container: ${{ matrix.container }}
107107
strategy:
108108
matrix:
109-
container: ['ubuntu:18.04', 'ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:22.10']
109+
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:22.10']
110110
env:
111111
DEBIAN_FRONTEND: noninteractive
112112
DEBFULLNAME: github-actions
113113
DEBEMAIL: github-actions@github.com
114114
steps:
115+
- name: Install dependencies
116+
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
115117
- name: Checkout
116-
uses: actions/checkout@v1
118+
uses: actions/checkout@v3
117119
with:
118120
submodules: recursive
119-
- name: Add open-eid repo
120-
if: matrix.container == 'ubuntu:18.04'
121-
run: |
122-
apt update -qq && apt install --no-install-recommends -y curl ca-certificates gnupg2 lsb-release
123-
curl https://installer.id.ee/media/install-scripts/C6C83D68.pub | gpg --dearmor | tee /etc/apt/trusted.gpg.d/ria-repository.gpg > /dev/null
124-
echo "deb https://installer.id.ee/media/ubuntu/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ria-repository.list
125-
- name: Install dependencies
126-
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
127121
- name: Setup changelog
128122
run: |
129123
export VERSION=$(grep project CMakeLists.txt | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")

CMakeLists.txt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.16)
22
project(libdigidocpp VERSION 3.15.0)
3-
if(POLICY CMP0074)
4-
cmake_policy(SET CMP0074 NEW)
5-
endif()
6-
if(POLICY CMP0078)
7-
cmake_policy(SET CMP0078 NEW)
8-
endif()
9-
if(POLICY CMP0086)
10-
cmake_policy(SET CMP0086 NEW)
11-
endif()
123
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
134

145
include(VersionInfo)
@@ -61,18 +52,6 @@ find_package(SWIG)
6152
find_package(JNI)
6253
find_package(Python3 COMPONENTS Interpreter Development)
6354

64-
if(Python3_FOUND)
65-
add_library(PythonModule INTERFACE)
66-
target_link_libraries(PythonModule INTERFACE Python3::Module)
67-
else()
68-
find_package(PythonLibs)
69-
if(PYTHONLIBS_FOUND)
70-
add_library(PythonModule INTERFACE)
71-
target_include_directories(PythonModule INTERFACE ${PYTHON_INCLUDE_DIRS})
72-
target_link_libraries(PythonModule INTERFACE ${PYTHON_LIBRARIES})
73-
endif()
74-
endif()
75-
7655
if( DOXYGEN_FOUND )
7756
configure_file( ${CMAKE_SOURCE_DIR}/etc/Doxyfile.in Doxyfile @ONLY )
7857
add_custom_target( docs ALL

src/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ target_link_libraries(digidocpp PRIVATE ${CMAKE_DL_LIBS} minizip digidocpp_priv)
245245

246246
if( BUILD_TOOLS )
247247
add_executable(digidoc-tool digidoc-tool.rc digidoc-tool.cpp)
248-
target_link_libraries(digidoc-tool digidocpp digidocpp_priv Threads::Threads
249-
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:-lstdc++fs>"
250-
)
248+
target_link_libraries(digidoc-tool digidocpp digidocpp_priv Threads::Threads)
251249
configure_file( digidoc-tool.1.cmake digidoc-tool.1 )
252250
endif()
253251

@@ -288,11 +286,11 @@ if(SWIG_FOUND)
288286
target_link_libraries(digidoc_java Iconv::Iconv)
289287
endif()
290288
endif()
291-
if(TARGET PythonModule)
289+
if(Python3_FOUND)
292290
set(CMAKE_SWIG_FLAGS -py3)
293291
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
294292
swig_add_library(digidoc_python TYPE SHARED LANGUAGE python SOURCES ../libdigidocpp.i)
295-
target_link_libraries(${SWIG_MODULE_digidoc_python_REAL_NAME} digidocpp digidocpp_util PythonModule)
293+
target_link_libraries(digidoc_python digidocpp digidocpp_util Python3::Module)
296294
#configure_file(setup.py.cmake setup.py)
297295
#install(CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)")
298296
if(NOT Python3_SITELIB)
@@ -304,9 +302,9 @@ if(SWIG_FOUND)
304302
set(Python3_SITELIB ${CMAKE_INSTALL_BINDIR})
305303
install(FILES $<TARGET_PDB_FILE:digidoc_python> DESTINATION ${Python3_SITELIB} OPTIONAL)
306304
else()
307-
set_target_properties(${SWIG_MODULE_digidoc_python_REAL_NAME} PROPERTIES SUFFIX .so)
305+
set_target_properties(digidoc_python PROPERTIES SUFFIX .so)
308306
endif()
309-
install(TARGETS ${SWIG_MODULE_digidoc_python_REAL_NAME} DESTINATION ${Python3_SITELIB})
307+
install(TARGETS digidoc_python DESTINATION ${Python3_SITELIB})
310308
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc.py DESTINATION ${Python3_SITELIB})
311309
endif()
312310
if(WIN32)

src/DataFile.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "util/File.h"
2424
#include "util/log.h"
2525

26+
#include <array>
2627
#include <fstream>
2728

2829
using namespace digidoc;
@@ -86,13 +87,11 @@ DataFile::DataFile() = default;
8687
DataFile::~DataFile() = default;
8788

8889

89-
DataFilePrivate::DataFilePrivate(unique_ptr<istream> is, string filename, string mediatype,
90-
string id, vector<unsigned char> digestValue)
90+
DataFilePrivate::DataFilePrivate(unique_ptr<istream> &&is, string filename, string mediatype, string id)
9191
: m_is(move(is))
9292
, m_id(move(id))
9393
, m_filename(move(filename))
9494
, m_mediatype(move(mediatype))
95-
, m_digestValue(move(digestValue))
9695
{
9796
m_is->seekg(0, istream::end);
9897
istream::pos_type pos = m_is->tellg();
@@ -101,16 +100,14 @@ DataFilePrivate::DataFilePrivate(unique_ptr<istream> is, string filename, string
101100

102101
vector<unsigned char> DataFilePrivate::calcDigest(const string &method) const
103102
{
104-
if(!m_digestValue.empty())
105-
return m_digestValue;
106103
Digest calc(method);
107104
calcDigest(&calc);
108105
return calc.result();
109106
}
110107

111108
void DataFilePrivate::calcDigest(Digest *digest) const
112109
{
113-
vector<unsigned char> buf(10240, 0);
110+
array<unsigned char, 10240> buf{};
114111
m_is->clear();
115112
m_is->seekg(0);
116113
while(*m_is)
@@ -125,7 +122,6 @@ void DataFilePrivate::saveAs(const string& path) const
125122
{
126123
ofstream ofs(File::encodeName(path).c_str(), ofstream::binary);
127124
saveAs(ofs);
128-
ofs.close();
129125
}
130126

131127
void DataFilePrivate::saveAs(ostream &os) const

src/DataFile_p.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,23 @@ namespace digidoc
2828
{
2929

3030
class Digest;
31-
class DataFilePrivate: public DataFile
31+
class DataFilePrivate final: public DataFile
3232
{
3333
public:
34-
DataFilePrivate(std::unique_ptr<std::istream> is, std::string filename, std::string mediatype, std::string id = {},
35-
std::vector<unsigned char> digestValue = {});
34+
DataFilePrivate(std::unique_ptr<std::istream> &&is, std::string filename, std::string mediatype, std::string id = {});
3635

37-
std::string id() const override { return m_id.empty() ? m_filename : m_id; }
38-
std::string fileName() const override { return m_filename; }
39-
unsigned long fileSize() const override { return m_size; }
40-
std::string mediaType() const override { return m_mediatype; }
36+
std::string id() const final { return m_id.empty() ? m_filename : m_id; }
37+
std::string fileName() const final { return m_filename; }
38+
unsigned long fileSize() const final { return m_size; }
39+
std::string mediaType() const final { return m_mediatype; }
4140

42-
std::vector<unsigned char> calcDigest(const std::string &method) const override;
41+
std::vector<unsigned char> calcDigest(const std::string &method) const final;
4342
void calcDigest(Digest *method) const;
44-
void saveAs(std::ostream &os) const override;
45-
void saveAs(const std::string& path) const override;
43+
void saveAs(std::ostream &os) const final;
44+
void saveAs(const std::string& path) const final;
4645

4746
std::unique_ptr<std::istream> m_is;
4847
std::string m_id, m_filename, m_mediatype;
49-
std::vector<unsigned char> m_digestValue;
5048
unsigned long m_size;
5149
};
5250
}

src/digidoc-tool.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@
3232
#include "util/log.h"
3333

3434
#include <algorithm>
35-
#include <cstdio>
36-
#include <cstdlib>
37-
#include <iomanip>
35+
#include <filesystem>
3836
#include <iostream>
39-
#include <map>
4037
#include <optional>
4138
#include <sstream>
4239

@@ -51,13 +48,7 @@
5148
using namespace digidoc;
5249
using namespace digidoc::util;
5350
using namespace std;
54-
#if __has_include(<filesystem>)
55-
#include <filesystem>
56-
namespace fs = std::filesystem;
57-
#else
58-
#include <experimental/filesystem>
59-
namespace fs = std::experimental::filesystem;
60-
#endif
51+
namespace fs = filesystem;
6152

6253
namespace std
6354
{
@@ -490,9 +481,8 @@ unique_ptr<Signer> ToolConfig::getSigner(bool getwebsigner) const
490481
win->setThumbprint(thumbprint);
491482
signer = unique_ptr<Signer>(win.release());
492483
}
493-
else
494484
#endif
495-
if(!pkcs12.empty())
485+
else if(!pkcs12.empty())
496486
signer = make_unique<PKCS12Signer>(pkcs12, pin);
497487
else
498488
signer = make_unique<ConsolePinSigner>(pkcs11, pin);

src/util/File.cpp

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <algorithm>
2525
#include <ctime>
26+
#include <filesystem>
2627
#include <locale>
2728
#include <sstream>
2829
#include <sys/stat.h>
@@ -45,6 +46,7 @@
4546
using namespace digidoc;
4647
using namespace digidoc::util;
4748
using namespace std;
49+
namespace fs = filesystem;
4850

4951
#ifdef _WIN32
5052
#define f_stat _wstat64
@@ -58,77 +60,6 @@ using f_statbuf = struct stat;
5860
using f_utimbuf = struct utimbuf;
5961
#endif
6062

61-
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
62-
#include <cerrno>
63-
#include <iconv.h>
64-
#include <cstdlib>
65-
#include <cstring>
66-
#include <langinfo.h>
67-
68-
/**
69-
* Helper method for converting from non-UTF-8 encoded strings to UTF-8.
70-
* Supported LANG values for Linux: see /usr/share/i18n/SUPPORTED.
71-
* Supported encodings for libiconv: see iconv --list .
72-
*
73-
* Note! If non-ASCII characters are used we assume a proper LANG value!!!
74-
*
75-
* @param str_in The string to be converted.
76-
* @return Returns the input string in UTF-8.
77-
*/
78-
string File::convertUTF8(string_view str_in, bool to_UTF)
79-
{
80-
string charset = nl_langinfo(CODESET);
81-
// no conversion needed for UTF-8
82-
if(charset == "UTF-8" || charset == "utf-8")
83-
return string(str_in);
84-
85-
iconv_t ic_descr = iconv_t(-1);
86-
try
87-
{
88-
ic_descr = to_UTF ? iconv_open("UTF-8", charset.c_str()) : iconv_open(charset.c_str(), "UTF-8");
89-
}
90-
catch(exception &) {}
91-
92-
if(ic_descr == iconv_t(-1))
93-
return string(str_in);
94-
95-
char* inptr = (char*)str_in.data();
96-
size_t inleft = str_in.size();
97-
98-
string out;
99-
char outbuf[64];
100-
char* outptr;
101-
size_t outleft;
102-
103-
while(inleft > 0)
104-
{
105-
outbuf[0] = '\0';
106-
outptr = (char *)outbuf;
107-
outleft = sizeof(outbuf) - sizeof(outbuf[0]);
108-
109-
size_t result = iconv(ic_descr, &inptr, &inleft, &outptr, &outleft);
110-
if(result == size_t(-1))
111-
{
112-
switch(errno)
113-
{
114-
case E2BIG: break;
115-
case EILSEQ:
116-
case EINVAL:
117-
default:
118-
iconv_close(ic_descr);
119-
return string(str_in);
120-
break;
121-
}
122-
}
123-
*outptr = '\0';
124-
out += outbuf;
125-
}
126-
iconv_close(ic_descr);
127-
128-
return out;
129-
}
130-
#endif
131-
13263
stack<string> File::tempFiles;
13364

13465
string File::confPath()
@@ -167,23 +98,15 @@ File::f_string File::encodeName(string_view fileName)
16798
{
16899
if(fileName.empty())
169100
return {};
170-
#if defined(_WIN32)
171-
int len = MultiByteToWideChar(CP_UTF8, 0, fileName.data(), int(fileName.size()), nullptr, 0);
172-
f_string out(size_t(len), 0);
173-
len = MultiByteToWideChar(CP_UTF8, 0, fileName.data(), int(fileName.size()), out.data(), len);
174-
#elif defined(__APPLE__)
175-
CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0);
176-
CFStringAppendCString(ref, fileName.data(), kCFStringEncodingUTF8);
177-
CFStringNormalize(ref, kCFStringNormalizationFormD);
178-
101+
#ifdef __APPLE__
102+
CFStringRef ref = CFStringCreateWithBytesNoCopy({}, (UInt8 *)fileName.data(),
103+
CFIndex(fileName.size()), kCFStringEncodingUTF8, FALSE, kCFAllocatorNull);
179104
string out(fileName.size() * 2, 0);
180-
CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8);
105+
CFStringGetFileSystemRepresentation(ref, out.data(), CFIndex(out.size()));
181106
CFRelease(ref);
182107
out.resize(strlen(out.c_str()));
183-
#elif defined(__ANDROID__)
184-
f_string out = string(fileName);
185108
#else
186-
f_string out = convertUTF8(fileName,false);
109+
f_string out = fs::u8path(fileName);
187110
#endif
188111
return out;
189112
}
@@ -197,11 +120,7 @@ string File::decodeName(const f_string_view &localFileName)
197120
{
198121
if(localFileName.empty())
199122
return {};
200-
#if defined(_WIN32)
201-
int len = WideCharToMultiByte(CP_UTF8, 0, localFileName.data(), int(localFileName.size()), nullptr, 0, nullptr, nullptr);
202-
string out(size_t(len), 0);
203-
WideCharToMultiByte(CP_UTF8, 0, localFileName.data(), int(localFileName.size()), out.data(), len, nullptr, nullptr);
204-
#elif defined(__APPLE__)
123+
#ifdef __APPLE__
205124
CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0);
206125
CFStringAppendCString(ref, localFileName.data(), kCFStringEncodingUTF8);
207126
CFStringNormalize(ref, kCFStringNormalizationFormC);
@@ -210,10 +129,8 @@ string File::decodeName(const f_string_view &localFileName)
210129
CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8);
211130
CFRelease(ref);
212131
out.resize(strlen(out.c_str()));
213-
#elif defined(__ANDROID__)
214-
string out = string(localFileName);
215132
#else
216-
string out = convertUTF8(localFileName,true);
133+
string out = fs::path(localFileName).u8string();
217134
#endif
218135
return out;
219136
}

src/util/File.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ namespace digidoc
7171
#endif
7272

7373
private:
74-
#if !defined(_WIN32) && !defined(__APPLE__)
75-
static std::string convertUTF8(std::string_view str_in, bool to_UTF);
76-
#endif
7774
static std::stack<std::string> tempFiles;
7875
};
7976

0 commit comments

Comments
 (0)