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
21 changes: 8 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
container: ubuntu:${{ matrix.container }}
strategy:
matrix:
container: ['22.04', '24.04', '24.10', '25.04']
container: ['22.04', '24.04', '25.04']
arch: ['amd64', 'arm64']
env:
DEBIAN_FRONTEND: noninteractive
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Prepare vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: 4008642a50a01a7115c2406b04d5273898e7fe1c
vcpkgGitCommitId: 031ad89ce6c575df35a8e58707ad2c898446c63e
vcpkgJsonGlob: ./vcpkg.json
runVcpkgInstall: true
env:
Expand Down Expand Up @@ -94,14 +94,12 @@ jobs:
- name: Install dependencies
run: |
brew update
brew install --formula flatbuffers swig doxygen boost [email protected]
brew unlink [email protected] || true
brew unlink [email protected] || true
brew install --formula flatbuffers swig doxygen boost
- name: Prepare vcpkg
if: matrix.target != 'macos'
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: 4008642a50a01a7115c2406b04d5273898e7fe1c
vcpkgGitCommitId: 031ad89ce6c575df35a8e58707ad2c898446c63e
vcpkgJsonGlob: ./vcpkg.json
runVcpkgInstall: true
env:
Expand All @@ -125,7 +123,7 @@ jobs:
runs-on: ${{ matrix.image }}
strategy:
matrix:
image: [windows-2022]
image: [windows-2025]
platform: [x64, arm64]
env:
CXXFLAGS: '/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' # https://github.com/actions/runner-images/issues/10004
Expand All @@ -137,17 +135,14 @@ jobs:
- name: Prepare vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: 4008642a50a01a7115c2406b04d5273898e7fe1c
vcpkgGitCommitId: 031ad89ce6c575df35a8e58707ad2c898446c63e
vcpkgJsonGlob: ./vcpkg.json
runVcpkgInstall: true
runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]"
env:
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/build/vcpkg_installed
- name: Install dependencies
run: |
choco install doxygen.install -y > $null
Invoke-WebRequest -UserAgent "Wget" "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.3.0/swigwin-4.3.0.zip/download" -OutFile swig.zip
tar xf swig.zip
run: winget install --silent --accept-source-agreements --accept-package-agreements swig doxygen
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
Expand All @@ -156,7 +151,7 @@ jobs:
run: |
cmake -A ${{ matrix.platform }} -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo `
"-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" `
"-DSWIG_EXECUTABLE=${{ github.workspace }}/swigwin-4.3.0/swig.exe" `
-DSWIG_EXECUTABLE=(Get-Item $env:LOCALAPPDATA\Microsoft\WinGet\Links\swig.exe).Target `
-DVCPKG_TARGET_TRIPLET=${{ env.VCPKG_DEFAULT_TRIPLET }} `
-DVCPKG_MANIFEST_FEATURES=tests `
-DCMAKE_INSTALL_LIBDIR=bin
Expand Down
4 changes: 2 additions & 2 deletions cdoc/Crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ Crypto::hkdf(const std::vector<uint8_t> &key, const std::vector<uint8_t> &salt,
SSL_FAILED(EVP_PKEY_CTX_hkdf_mode(ctx.get(), mode), "EVP_PKEY_CTX_hkdf_mode") ||
SSL_FAILED(EVP_PKEY_CTX_set_hkdf_md(ctx.get(), EVP_sha256()), "EVP_PKEY_CTX_set_hkdf_md") ||
SSL_FAILED(EVP_PKEY_CTX_set1_hkdf_key(ctx.get(), key.data(), int(key.size())), "EVP_PKEY_CTX_set1_hkdf_key") ||
SSL_FAILED(EVP_PKEY_CTX_set1_hkdf_salt(ctx.get(), salt.data(), int(salt.size())), "EVP_PKEY_CTX_set1_hkdf_salt") ||
SSL_FAILED(EVP_PKEY_CTX_add1_hkdf_info(ctx.get(), info.data(), int(info.size())), "EVP_PKEY_CTX_add1_hkdf_info") ||
(!salt.empty() && SSL_FAILED(EVP_PKEY_CTX_set1_hkdf_salt(ctx.get(), salt.data(), int(salt.size())), "EVP_PKEY_CTX_set1_hkdf_salt")) ||
(!info.empty() && SSL_FAILED(EVP_PKEY_CTX_add1_hkdf_info(ctx.get(), info.data(), int(info.size())), "EVP_PKEY_CTX_add1_hkdf_info")) ||
SSL_FAILED(EVP_PKEY_derive(ctx.get(), out.data(), &outlen), "EVP_PKEY_derive"))
return {};

Expand Down
25 changes: 8 additions & 17 deletions cdoc/DDocWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,27 @@ using namespace libcdoc;
* @brief DDOCWriter is used for storing multiple files.
*/

struct DDOCWriter::Private
{
static const NS DDOC;
int fileCount = 0;
};

const XMLWriter::NS DDOCWriter::Private::DDOC{ "", "http://www.sk.ee/DigiDoc/v1.3.0#" };
const XMLWriter::NS DDOCWriter::DDOC{ "", "http://www.sk.ee/DigiDoc/v1.3.0#" };

/**
* DDOCWriter constructor.
* @param file File to be created
*/
DDOCWriter::DDOCWriter(const std::string &file)
: XMLWriter(file)
, d(new Private)
{
writeStartElement(Private::DDOC, "SignedDoc", {{"format", "DIGIDOC-XML"}, {"version", "1.3"}});
writeStartElement(DDOC, "SignedDoc", {{"format", "DIGIDOC-XML"}, {"version", "1.3"}});
}

DDOCWriter::DDOCWriter(std::vector<uint8_t>& vec)
: XMLWriter(vec),
d(new Private)
: XMLWriter(vec)
{
writeStartElement(Private::DDOC, "SignedDoc", {{"format", "DIGIDOC-XML"}, {"version", "1.3"}});
writeStartElement(DDOC, "SignedDoc", {{"format", "DIGIDOC-XML"}, {"version", "1.3"}});
}

DDOCWriter::~DDOCWriter()
{
writeEndElement(Private::DDOC); // SignedDoc
delete d;
writeEndElement(DDOC); // SignedDoc
}

/**
Expand All @@ -63,12 +54,12 @@ DDOCWriter::~DDOCWriter()
* @param mime File mime type
* @param data File content
*/
void DDOCWriter::addFile(const std::string &file, const std::string &mime, const std::vector<unsigned char> &data)
uint64_t DDOCWriter::addFile(const std::string &file, const std::string &mime, const std::vector<unsigned char> &data)
{
writeBase64Element(Private::DDOC, "DataFile", data, {
return writeBase64Element(DDOC, "DataFile", data, {
{"ContentType", "EMBEDDED_BASE64"},
{"Filename", file},
{"Id", "D" + std::to_string(d->fileCount++)},
{"Id", "D" + std::to_string(fileCount++)},
{"MimeType", mime},
{"Size", std::to_string(data.size())}
});
Expand Down
7 changes: 4 additions & 3 deletions cdoc/DDocWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ class DDOCWriter: public XMLWriter
DDOCWriter(std::vector<uint8_t>& vec);
~DDOCWriter();

void addFile(const std::string &name, const std::string &mime, const std::vector<unsigned char> &data);
uint64_t addFile(const std::string &name, const std::string &mime, const std::vector<unsigned char> &data);

private:
DDOCWriter(const DDOCWriter &) = delete;
DDOCWriter &operator=(const DDOCWriter &) = delete;
struct Private;
Private *d;
int fileCount = 0;

static const NS DDOC;
};

}
79 changes: 38 additions & 41 deletions cdoc/XmlWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

#include "XmlWriter.h"

#include "Utils.h"
#include "Io.h"

#include <openssl/evp.h>
#include <libxml/xmlwriter.h>

using namespace libcdoc;
Expand Down Expand Up @@ -81,72 +80,70 @@ XMLWriter::~XMLWriter()
delete d;
}

void XMLWriter::writeStartElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr)
int64_t XMLWriter::writeStartElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr)
{
if(!d->w)
return WRONG_ARGUMENTS;
std::map<std::string, int>::iterator pos = d->nsmap.find(ns.prefix);
if (pos != d->nsmap.cend())
pos->second++;
else
pos = d->nsmap.insert({ns.prefix, 1}).first;
if(!d->w)
return;
if(xmlTextWriterStartElementNS(d->w, ns.prefix.empty() ? nullptr : pcxmlChar(ns.prefix.c_str()),
pcxmlChar(name.c_str()), pos->second > 1 ? nullptr : pcxmlChar(ns.ns.c_str())) < 0)
return;
if(xmlTextWriterStartElementNS(d->w, ns.prefix.empty() ? nullptr : pcxmlChar(ns.prefix.c_str()),
pcxmlChar(name.c_str()), pos->second > 1 ? nullptr : pcxmlChar(ns.ns.c_str())) == -1)
return IO_ERROR;
for(auto i = attr.cbegin(), end = attr.cend(); i != end; ++i)
{
if(xmlTextWriterWriteAttribute(d->w, pcxmlChar(i->first.c_str()), pcxmlChar(i->second.c_str())) < 0)
break;
if(xmlTextWriterWriteAttribute(d->w, pcxmlChar(i->first.c_str()), pcxmlChar(i->second.c_str())) == -1)
return IO_ERROR;
}
return OK;
}

void XMLWriter::writeEndElement(const NS &ns)
int64_t XMLWriter::writeEndElement(const NS &ns)
{
if(d->w)
xmlTextWriterEndElement(d->w);
std::map<std::string, int>::iterator pos = d->nsmap.find(ns.prefix);
if (pos != d->nsmap.cend())
if(!d->w)
return WRONG_ARGUMENTS;
if(xmlTextWriterEndElement(d->w) == -1)
return IO_ERROR;
if(std::map<std::string, int>::iterator pos = d->nsmap.find(ns.prefix);
pos != d->nsmap.cend())
pos->second--;
return OK;
}

void XMLWriter::writeElement(const NS &ns, const std::string &name, const std::function<void()> &f)
int64_t XMLWriter::writeElement(const NS &ns, const std::string &name, const std::function<void()> &f)
{
writeStartElement(ns, name, {});
if(auto rv = writeStartElement(ns, name, {}); rv != OK)
return rv;
if(f)
f();
writeEndElement(ns);
return writeEndElement(ns);
}

void XMLWriter::writeElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::function<void()> &f)
int64_t XMLWriter::writeElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::function<void()> &f)
{
writeStartElement(ns, name, attr);
if(auto rv = writeStartElement(ns, name, attr); rv != OK)
return rv;
if(f)
f();
writeEndElement(ns);
return writeEndElement(ns);
}

void XMLWriter::writeBase64Element(const NS &ns, const std::string &name, const std::vector<xmlChar> &data, const std::map<std::string, std::string> &attr)
int64_t XMLWriter::writeBase64Element(const NS &ns, const std::string &name, const std::vector<xmlChar> &data, const std::map<std::string, std::string> &attr)
{
if (!d->w)
return;
static const size_t bufLen = 48 * 10240;
std::vector<xmlChar> result(((bufLen + 2) / 3) * 4, 0);
writeStartElement(ns, name, attr);
for (size_t i = 0; i < data.size(); i += bufLen)
{
int size = EVP_EncodeBlock(result.data(), &data[i], std::min(data.size() - i, bufLen));
if(size == 0)
break;
if(xmlTextWriterWriteRawLen(d->w, result.data(), size) < 0)
break;
}
writeEndElement(ns);
if(auto rv = writeStartElement(ns, name, attr); rv != OK)
return rv;
if(xmlTextWriterWriteBase64(d->w, reinterpret_cast<const char*>(data.data()), 0, data.size()) == -1)
return IO_ERROR;
return writeEndElement(ns);
}

void XMLWriter::writeTextElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::string &data)
int64_t XMLWriter::writeTextElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::string &data)
{
writeStartElement(ns, name, attr);
if(d->w)
(void)xmlTextWriterWriteString(d->w, pcxmlChar(data.c_str()));
writeEndElement(ns);
if(auto rv = writeStartElement(ns, name, attr); rv != OK)
return rv;
if(xmlTextWriterWriteString(d->w, pcxmlChar(data.c_str())) == -1)
return IO_ERROR;
return writeEndElement(ns);
}
12 changes: 6 additions & 6 deletions cdoc/XmlWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class XMLWriter
XMLWriter(DataConsumer *dst);
virtual ~XMLWriter();

void writeStartElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr);
void writeEndElement(const NS &ns);
void writeElement(const NS &ns, const std::string &name, const std::function<void()> &f = nullptr);
void writeElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::function<void()> &f = nullptr);
void writeBase64Element(const NS &ns, const std::string &name, const std::vector<unsigned char> &data, const std::map<std::string, std::string> &attr = {});
void writeTextElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::string &data);
int64_t writeStartElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr);
int64_t writeEndElement(const NS &ns);
int64_t writeElement(const NS &ns, const std::string &name, const std::function<void()> &f = nullptr);
int64_t writeElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::function<void()> &f = nullptr);
int64_t writeBase64Element(const NS &ns, const std::string &name, const std::vector<unsigned char> &data, const std::map<std::string, std::string> &attr = {});
int64_t writeTextElement(const NS &ns, const std::string &name, const std::map<std::string, std::string> &attr, const std::string &data);

private:
struct Private;
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"features": {
"tests": { "description": "Build tests", "dependencies": ["boost-test"] }
},
"builtin-baseline": "4008642a50a01a7115c2406b04d5273898e7fe1c",
"builtin-baseline": "031ad89ce6c575df35a8e58707ad2c898446c63e",
"vcpkg-configuration": {
"overlay-triplets": ["./vcpkg-triplets"]
}
Expand Down
Loading