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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ jobs:
name: Deploy pages
if: github.repository == 'open-eid/libdigidocpp' && contains(github.ref, 'master')
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
5 changes: 3 additions & 2 deletions etc/digidocpp.conf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
<!--Verify service settings-->
<!--<param name="verify.serivceUri" lock="false">@SIVA_URL@</param>-->

<!--OCSP BDoc-TM validation settings-->
<!--<param name="ocsp.tm.profile" lock="false">1.3.6.1.4.1.10015.4.1.2</param>-->

<!--OCSP responder URL-->
<!--<ocsp issuer="ESTEID-SK 2015">http://ocsp.sk.ee</ocsp>-->
<!--<ocsp issuer="KLASS3-SK 2010">http://ocsp.sk.ee</ocsp>-->
<!--<ocsp issuer="KLASS3-SK 2016">http://ocsp.sk.ee</ocsp>-->
</configuration>
4 changes: 1 addition & 3 deletions src/Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ string Conf::PKCS11Driver() const { return PKCS11_MODULE; }
*/
string Conf::ocsp(const string &issuer) const
{
static const map<string,string> ocsplist = {
static const map<string_view,string> ocsplist = {
{"ESTEID-SK 2015", "http://ocsp.sk.ee"},
{"KLASS3-SK 2010", "http://ocsp.sk.ee"},
{"KLASS3-SK 2016", "http://ocsp.sk.ee"},
};
auto pos = ocsplist.find(issuer);
return pos == ocsplist.end() ? string() : pos->second;
Expand Down
30 changes: 15 additions & 15 deletions src/util/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ using f_utimbuf = struct utimbuf;
* @param str_in The string to be converted.
* @return Returns the input string in UTF-8.
*/
string File::convertUTF8(const string &str_in, bool to_UTF)
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 str_in;
return string(str_in);

iconv_t ic_descr = iconv_t(-1);
try
Expand All @@ -90,9 +90,9 @@ string File::convertUTF8(const string &str_in, bool to_UTF)
catch(exception &) {}

if(ic_descr == iconv_t(-1))
return str_in;
return string(str_in);

char* inptr = (char*)str_in.c_str();
char* inptr = (char*)str_in.data();
size_t inleft = str_in.size();

string out;
Expand All @@ -116,7 +116,7 @@ string File::convertUTF8(const string &str_in, bool to_UTF)
case EINVAL:
default:
iconv_close(ic_descr);
return str_in;
return string(str_in);
break;
}
}
Expand Down Expand Up @@ -144,15 +144,15 @@ string File::confPath()
#endif
}

string File::env(const string &varname)
string File::env(string_view varname)
{
#ifdef _WIN32
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
return {};
#endif
if(wchar_t *var = _wgetenv(encodeName(varname).c_str()))
#else
if(char *var = getenv(encodeName(varname).c_str()))
if(char *var = getenv(varname.data()))
#endif
return decodeName(var);
return {};
Expand All @@ -163,7 +163,7 @@ string File::env(const string &varname)
* @param fileName path
* @return encoded path
*/
File::f_string File::encodeName(const string &fileName)
File::f_string File::encodeName(string_view fileName)
{
if(fileName.empty())
return {};
Expand All @@ -173,15 +173,15 @@ File::f_string File::encodeName(const string &fileName)
len = MultiByteToWideChar(CP_UTF8, 0, fileName.data(), int(fileName.size()), out.data(), len);
#elif defined(__APPLE__)
CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0);
CFStringAppendCString(ref, fileName.c_str(), kCFStringEncodingUTF8);
CFStringAppendCString(ref, fileName.data(), kCFStringEncodingUTF8);
CFStringNormalize(ref, kCFStringNormalizationFormD);

string out(fileName.size() * 2, 0);
CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8);
CFRelease(ref);
out.resize(strlen(out.c_str()));
#elif defined(__ANDROID__)
f_string out = fileName;
f_string out = string(fileName);
#else
f_string out = convertUTF8(fileName,false);
#endif
Expand All @@ -193,7 +193,7 @@ File::f_string File::encodeName(const string &fileName)
* @param localFileName path
* @return decoded path
*/
string File::decodeName(const f_string &localFileName)
string File::decodeName(const f_string_view &localFileName)
{
if(localFileName.empty())
return {};
Expand All @@ -203,15 +203,15 @@ string File::decodeName(const f_string &localFileName)
WideCharToMultiByte(CP_UTF8, 0, localFileName.data(), int(localFileName.size()), out.data(), len, nullptr, nullptr);
#elif defined(__APPLE__)
CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0);
CFStringAppendCString(ref, localFileName.c_str(), kCFStringEncodingUTF8);
CFStringAppendCString(ref, localFileName.data(), kCFStringEncodingUTF8);
CFStringNormalize(ref, kCFStringNormalizationFormC);

string out(localFileName.size() * 2, 0);
CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8);
CFRelease(ref);
out.resize(strlen(out.c_str()));
#elif defined(__ANDROID__)
string out = localFileName;
string out = string(localFileName);
#else
string out = convertUTF8(localFileName,true);
#endif
Expand Down Expand Up @@ -343,7 +343,7 @@ string File::path(const string& directory, const string& relativePath)
{
string dir(directory);
if(!dir.empty() && (dir[dir.size() - 1] == '/' || dir[dir.size() - 1] == '\\'))
dir = dir.substr(0, dir.size() - 1);
dir.pop_back();

string path = dir + "/" + relativePath;
#ifdef _WIN32
Expand Down Expand Up @@ -392,7 +392,7 @@ void File::createDirectory(const string& path)

string dirPath = path;
if(dirPath[dirPath.size() - 1] == '/' || dirPath[dirPath.size() - 1] == '\\')
dirPath = dirPath.substr(0, dirPath.size() - 1);
dirPath.pop_back();

f_string _path = encodeName(dirPath);
f_statbuf fileInfo;
Expand Down
10 changes: 6 additions & 4 deletions src/util/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ namespace digidoc
public:
#ifdef _WIN32
using f_string = std::wstring;
using f_string_view = std::wstring_view;
#else
using f_string = std::string;
using f_string_view = std::string_view;
#endif
static std::string confPath();
static std::string env(const std::string &varname);
static std::string env(std::string_view varname);
static bool fileExists(const std::string& path);
static f_string encodeName(const std::string &fileName);
static std::string decodeName(const f_string &localFileName);
static f_string encodeName(std::string_view fileName);
static std::string decodeName(const f_string_view &localFileName);
static bool isRelative(const std::string &path);
static time_t modifiedTime(const std::string &path);
static void updateModifiedTime(const std::string &path, time_t time);
Expand All @@ -70,7 +72,7 @@ namespace digidoc

private:
#if !defined(_WIN32) && !defined(__APPLE__)
static std::string convertUTF8(const std::string &str_in, bool to_UTF);
static std::string convertUTF8(std::string_view str_in, bool to_UTF);
#endif
static std::stack<std::string> tempFiles;
};
Expand Down