diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40bda604..2c2b2c1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -59,7 +59,7 @@ jobs: - name: Prepare vcpkg uses: lukka/run-vcpkg@v11 with: - vcpkgGitCommitId: 4008642a50a01a7115c2406b04d5273898e7fe1c + vcpkgGitCommitId: 031ad89ce6c575df35a8e58707ad2c898446c63e vcpkgJsonGlob: ./vcpkg.json runVcpkgInstall: true env: @@ -94,14 +94,12 @@ jobs: - name: Install dependencies run: | brew update - brew install --formula flatbuffers swig doxygen boost openssl@3.0 - brew unlink python@3.12 || true - brew unlink python@3.13 || 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: @@ -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 @@ -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' @@ -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 diff --git a/cdoc/Crypto.cpp b/cdoc/Crypto.cpp index 9e5ca6bd..7f372921 100644 --- a/cdoc/Crypto.cpp +++ b/cdoc/Crypto.cpp @@ -407,8 +407,8 @@ Crypto::hkdf(const std::vector &key, const std::vector &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 {}; diff --git a/cdoc/DDocWriter.cpp b/cdoc/DDocWriter.cpp index cc279daf..573f8c69 100644 --- a/cdoc/DDocWriter.cpp +++ b/cdoc/DDocWriter.cpp @@ -25,13 +25,7 @@ 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. @@ -39,22 +33,19 @@ const XMLWriter::NS DDOCWriter::Private::DDOC{ "", "http://www.sk.ee/DigiDoc/v1. */ 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& 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 } /** @@ -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 &data) +uint64_t DDOCWriter::addFile(const std::string &file, const std::string &mime, const std::vector &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())} }); diff --git a/cdoc/DDocWriter.h b/cdoc/DDocWriter.h index 578b605a..bdd89045 100644 --- a/cdoc/DDocWriter.h +++ b/cdoc/DDocWriter.h @@ -29,13 +29,14 @@ class DDOCWriter: public XMLWriter DDOCWriter(std::vector& vec); ~DDOCWriter(); - void addFile(const std::string &name, const std::string &mime, const std::vector &data); + uint64_t addFile(const std::string &name, const std::string &mime, const std::vector &data); private: DDOCWriter(const DDOCWriter &) = delete; DDOCWriter &operator=(const DDOCWriter &) = delete; - struct Private; - Private *d; + int fileCount = 0; + + static const NS DDOC; }; } \ No newline at end of file diff --git a/cdoc/XmlWriter.cpp b/cdoc/XmlWriter.cpp index 231923cb..bc76535b 100644 --- a/cdoc/XmlWriter.cpp +++ b/cdoc/XmlWriter.cpp @@ -18,9 +18,8 @@ #include "XmlWriter.h" -#include "Utils.h" +#include "Io.h" -#include #include using namespace libcdoc; @@ -81,72 +80,70 @@ XMLWriter::~XMLWriter() delete d; } -void XMLWriter::writeStartElement(const NS &ns, const std::string &name, const std::map &attr) +int64_t XMLWriter::writeStartElement(const NS &ns, const std::string &name, const std::map &attr) { + if(!d->w) + return WRONG_ARGUMENTS; std::map::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::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::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 &f) +int64_t XMLWriter::writeElement(const NS &ns, const std::string &name, const std::function &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 &attr, const std::function &f) +int64_t XMLWriter::writeElement(const NS &ns, const std::string &name, const std::map &attr, const std::function &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 &data, const std::map &attr) +int64_t XMLWriter::writeBase64Element(const NS &ns, const std::string &name, const std::vector &data, const std::map &attr) { - if (!d->w) - return; - static const size_t bufLen = 48 * 10240; - std::vector 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(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 &attr, const std::string &data) +int64_t XMLWriter::writeTextElement(const NS &ns, const std::string &name, const std::map &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); } diff --git a/cdoc/XmlWriter.h b/cdoc/XmlWriter.h index 30fe8251..1dbf650b 100644 --- a/cdoc/XmlWriter.h +++ b/cdoc/XmlWriter.h @@ -39,12 +39,12 @@ class XMLWriter XMLWriter(DataConsumer *dst); virtual ~XMLWriter(); - void writeStartElement(const NS &ns, const std::string &name, const std::map &attr); - void writeEndElement(const NS &ns); - void writeElement(const NS &ns, const std::string &name, const std::function &f = nullptr); - void writeElement(const NS &ns, const std::string &name, const std::map &attr, const std::function &f = nullptr); - void writeBase64Element(const NS &ns, const std::string &name, const std::vector &data, const std::map &attr = {}); - void writeTextElement(const NS &ns, const std::string &name, const std::map &attr, const std::string &data); + int64_t writeStartElement(const NS &ns, const std::string &name, const std::map &attr); + int64_t writeEndElement(const NS &ns); + int64_t writeElement(const NS &ns, const std::string &name, const std::function &f = nullptr); + int64_t writeElement(const NS &ns, const std::string &name, const std::map &attr, const std::function &f = nullptr); + int64_t writeBase64Element(const NS &ns, const std::string &name, const std::vector &data, const std::map &attr = {}); + int64_t writeTextElement(const NS &ns, const std::string &name, const std::map &attr, const std::string &data); private: struct Private; diff --git a/vcpkg.json b/vcpkg.json index e0bd2d65..837139d8 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -21,7 +21,7 @@ "features": { "tests": { "description": "Build tests", "dependencies": ["boost-test"] } }, - "builtin-baseline": "4008642a50a01a7115c2406b04d5273898e7fe1c", + "builtin-baseline": "031ad89ce6c575df35a8e58707ad2c898446c63e", "vcpkg-configuration": { "overlay-triplets": ["./vcpkg-triplets"] }