Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,}")
Expand Down
23 changes: 1 addition & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:-lstdc++fs>"
)
target_link_libraries(digidoc-tool digidocpp digidocpp_priv Threads::Threads)
configure_file( digidoc-tool.1.cmake digidoc-tool.1 )
endif()

Expand Down Expand Up @@ -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)
Expand All @@ -304,9 +302,9 @@ if(SWIG_FOUND)
set(Python3_SITELIB ${CMAKE_INSTALL_BINDIR})
install(FILES $<TARGET_PDB_FILE:digidoc_python> 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)
Expand Down
10 changes: 3 additions & 7 deletions src/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "util/File.h"
#include "util/log.h"

#include <array>
#include <fstream>

using namespace digidoc;
Expand Down Expand Up @@ -86,13 +87,11 @@ DataFile::DataFile() = default;
DataFile::~DataFile() = default;


DataFilePrivate::DataFilePrivate(unique_ptr<istream> is, string filename, string mediatype,
string id, vector<unsigned char> digestValue)
DataFilePrivate::DataFilePrivate(unique_ptr<istream> &&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();
Expand All @@ -101,16 +100,14 @@ DataFilePrivate::DataFilePrivate(unique_ptr<istream> is, string filename, string

vector<unsigned char> DataFilePrivate::calcDigest(const string &method) const
{
if(!m_digestValue.empty())
return m_digestValue;
Digest calc(method);
calcDigest(&calc);
return calc.result();
}

void DataFilePrivate::calcDigest(Digest *digest) const
{
vector<unsigned char> buf(10240, 0);
array<unsigned char, 10240> buf{};
m_is->clear();
m_is->seekg(0);
while(*m_is)
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions src/DataFile_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ namespace digidoc
{

class Digest;
class DataFilePrivate: public DataFile
class DataFilePrivate final: public DataFile
{
public:
DataFilePrivate(std::unique_ptr<std::istream> is, std::string filename, std::string mediatype, std::string id = {},
std::vector<unsigned char> digestValue = {});
DataFilePrivate(std::unique_ptr<std::istream> &&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<unsigned char> calcDigest(const std::string &method) const override;
std::vector<unsigned char> 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<std::istream> m_is;
std::string m_id, m_filename, m_mediatype;
std::vector<unsigned char> m_digestValue;
unsigned long m_size;
};
}
16 changes: 3 additions & 13 deletions src/digidoc-tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
#include "util/log.h"

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <filesystem>
#include <iostream>
#include <map>
#include <optional>
#include <sstream>

Expand All @@ -51,13 +48,7 @@
using namespace digidoc;
using namespace digidoc::util;
using namespace std;
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
namespace fs = filesystem;

namespace std
{
Expand Down Expand Up @@ -490,9 +481,8 @@ unique_ptr<Signer> ToolConfig::getSigner(bool getwebsigner) const
win->setThumbprint(thumbprint);
signer = unique_ptr<Signer>(win.release());
}
else
#endif
if(!pkcs12.empty())
else if(!pkcs12.empty())
signer = make_unique<PKCS12Signer>(pkcs12, pin);
else
signer = make_unique<ConsolePinSigner>(pkcs11, pin);
Expand Down
101 changes: 9 additions & 92 deletions src/util/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <algorithm>
#include <ctime>
#include <filesystem>
#include <locale>
#include <sstream>
#include <sys/stat.h>
Expand All @@ -45,6 +46,7 @@
using namespace digidoc;
using namespace digidoc::util;
using namespace std;
namespace fs = filesystem;

#ifdef _WIN32
#define f_stat _wstat64
Expand All @@ -58,77 +60,6 @@ using f_statbuf = struct stat;
using f_utimbuf = struct utimbuf;
#endif

#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
#include <cerrno>
#include <iconv.h>
#include <cstdlib>
#include <cstring>
#include <langinfo.h>

/**
* 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<string> File::tempFiles;

string File::confPath()
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/util/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> tempFiles;
};

Expand Down