vcl/source/gdi/pdfwriter_impl.cxx |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

New commits:
commit a0ff88da40c2fdc20a069e686230506e41b2ebc5
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Nov 8 11:56:25 2024 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Nov 26 01:35:25 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/+/176891
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Jenkins

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index b282827ee4c3..71c097d6b36e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -353,14 +353,6 @@ public:
         maLine.append(value);
     }
 
-    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)
     {
         maLine.append(key);
@@ -372,6 +364,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
@@ -6143,6 +6146,7 @@ sal_Int32 PDFWriterImpl::emitEncrypt()
 
     if (updateObject(nObject))
     {
+        PDFEncryptionProperties& rProperties = m_aContext.Encryption;
         PDFStructureWriter aWriter(*this);
         aWriter.startObject(nObject);
         aWriter.startDict();
@@ -6151,8 +6155,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();

Reply via email to