vcl/source/gdi/pdfwriter_impl.cxx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
New commits: commit 77c882bb1929e026c05ba4f32b37a5e42fbc191a Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Nov 8 11:56:25 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Nov 29 09:53:14 2024 +0100 pdf: write encrption O and U values as hex string This is easier to evaluate when opening the file in text editor than binary. It is also more common in other PDF writers to use it as hex string. There is no problem with viewers. Change-Id: Ie453556d22695017916c7953f91c499e3d990b0c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176449 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index e80af24f1679..a28a919ff7f6 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -352,13 +352,13 @@ public: maLine.append(value); } - void writeString(std::string_view key, char* pString, sal_Int32 nSize) + /*void writeString(std::string_view key, char* pString, sal_Int32 nSize) { maLine.append(key); maLine.append(" ("); appendLiteralString(pString, nSize, maLine); maLine.append(")"); - } + }*/ void writeUnicodeEncrypt(std::string_view key, OUString const& rString, sal_Int32 nObject) { @@ -371,6 +371,17 @@ public: maLine.append(key); mrWriterImpl.appendLiteralStringEncrypt(value, nObject, maLine); } + + void writeHexArray(std::string_view key, sal_uInt8* pData, size_t nSize) + { + maLine.append(key); + maLine.append(" <"); + for (size_t i = 0; i < nSize; i++) + { + appendHex(sal_Int8(pData[i]), maLine); + } + maLine.append(">"); + } }; } // end anonymous namespace @@ -6093,6 +6104,7 @@ sal_Int32 PDFWriterImpl::emitEncrypt() if (updateObject(nObject)) { + PDFEncryptionProperties& rProperties = m_aContext.Encryption; PDFStructureWriter aWriter(*this); aWriter.startObject(nObject); aWriter.startDict(); @@ -6101,8 +6113,8 @@ sal_Int32 PDFWriterImpl::emitEncrypt() aWriter.write("/Length", 128); aWriter.write("/R", 3); // emit the owner password, must not be encrypted - aWriter.writeString("/O", reinterpret_cast<char*>(m_aContext.Encryption.OValue.data()), sal_Int32(m_aContext.Encryption.OValue.size())); - aWriter.writeString("/U", reinterpret_cast<char*>(m_aContext.Encryption.UValue.data()), sal_Int32(m_aContext.Encryption.UValue.size())); + aWriter.writeHexArray("/O", rProperties.OValue.data(), rProperties.OValue.size()); + aWriter.writeHexArray("/U", rProperties.UValue.data(), rProperties.UValue.size()); aWriter.write("/P", m_pPDFEncryptor->getAccessPermissions()); aWriter.endDict(); aWriter.endObject();