[Libreoffice-commits] core.git: include/vcl vcl/source xmlsecurity/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Nov 26 08:06:52 UTC 2020


 include/vcl/filter/PDFiumLibrary.hxx             |    5 ++
 vcl/source/pdf/PDFiumLibrary.cxx                 |   41 +++++++++++++++++++++++
 xmlsecurity/source/helper/pdfsignaturehelper.cxx |   28 +--------------
 3 files changed, 47 insertions(+), 27 deletions(-)

New commits:
commit 7ca0f29249eb11623c98efdc4fb6d0d7725ff10a
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Nov 25 21:08:32 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 26 09:06:04 2020 +0100

    pdfium: replace PDFiumSignature::getPointer() with typed getters
    
    Once reason and time has getters, no need to expose the underlying
    PDFium type.
    
    Change-Id: I8f6b152fddf38e76ad7c3b1897fcb2026129820f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106631
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index e14c855780b7..1fe0dd8d988a 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -12,6 +12,8 @@
 
 #include <config_features.h>
 
+#include <com/sun/star/util/DateTime.hpp>
+
 #if HAVE_FEATURE_PDFIUM
 
 #include <vcl/dllapi.h>
@@ -241,11 +243,12 @@ private:
 public:
     PDFiumSignature(FPDF_SIGNATURE pSignature);
 
-    FPDF_SIGNATURE getPointer() { return mpSignature; }
     std::vector<int> getByteRange();
     int getDocMDPPermission();
     std::vector<unsigned char> getContents();
     OString getSubFilter();
+    OUString getReason();
+    css::util::DateTime getTime();
 };
 
 class VCL_DLLPUBLIC PDFiumDocument final
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index a1d618e33105..5c308d3e772b 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -27,6 +27,8 @@
 
 #include <bitmapwriteaccess.hxx>
 
+using namespace com::sun::star;
+
 static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Unknown) == FPDF_PAGEOBJ_UNKNOWN,
               "PDFPageObjectType::Unknown value mismatch");
 static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Text) == FPDF_PAGEOBJ_TEXT,
@@ -237,6 +239,45 @@ OString PDFiumSignature::getSubFilter()
     return aSubFilter;
 }
 
+OUString PDFiumSignature::getReason()
+{
+    int nReasonLen = FPDFSignatureObj_GetReason(mpSignature, nullptr, 0);
+    OUString aRet;
+    if (nReasonLen > 0)
+    {
+        std::vector<char16_t> aReasonBuf(nReasonLen);
+        FPDFSignatureObj_GetReason(mpSignature, aReasonBuf.data(), aReasonBuf.size());
+        aRet = OUString(aReasonBuf.data(), aReasonBuf.size() - 1);
+    }
+
+    return aRet;
+}
+
+util::DateTime PDFiumSignature::getTime()
+{
+    util::DateTime aRet;
+    int nTimeLen = FPDFSignatureObj_GetTime(mpSignature, nullptr, 0);
+    if (nTimeLen <= 0)
+    {
+        return aRet;
+    }
+
+    // Example: "D:20161027100104".
+    std::vector<char> aTimeBuf(nTimeLen);
+    FPDFSignatureObj_GetTime(mpSignature, aTimeBuf.data(), aTimeBuf.size());
+    OString aM(aTimeBuf.data(), aTimeBuf.size() - 1);
+    if (aM.startsWith("D:") && aM.getLength() >= 16)
+    {
+        aRet.Year = aM.copy(2, 4).toInt32();
+        aRet.Month = aM.copy(6, 2).toInt32();
+        aRet.Day = aM.copy(8, 2).toInt32();
+        aRet.Hours = aM.copy(10, 2).toInt32();
+        aRet.Minutes = aM.copy(12, 2).toInt32();
+        aRet.Seconds = aM.copy(14, 2).toInt32();
+    }
+    return aRet;
+}
+
 PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument)
     : mpPdfDocument(pPdfDocument)
 {
diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
index 062dba819adf..cbeba392a932 100644
--- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
@@ -366,35 +366,11 @@ bool ValidateSignature(SvStream& rStream, const Signature& rSignature,
     }
 
     // Reason / comment / description is optional.
-    int nReasonLen = FPDFSignatureObj_GetReason(rSignature.m_pSignature->getPointer(), nullptr, 0);
-    if (nReasonLen > 0)
-    {
-        std::vector<char16_t> aReasonBuf(nReasonLen);
-        FPDFSignatureObj_GetReason(rSignature.m_pSignature->getPointer(), aReasonBuf.data(),
-                                   aReasonBuf.size());
-        rInformation.ouDescription = OUString(aReasonBuf.data(), aReasonBuf.size() - 1);
-    }
+    rInformation.ouDescription = rSignature.m_pSignature->getReason();
 
     // Date: used only when the time of signing is not available in the
     // signature.
-    int nTimeLen = FPDFSignatureObj_GetTime(rSignature.m_pSignature->getPointer(), nullptr, 0);
-    if (nTimeLen > 0)
-    {
-        // Example: "D:20161027100104".
-        std::vector<char> aTimeBuf(nTimeLen);
-        FPDFSignatureObj_GetTime(rSignature.m_pSignature->getPointer(), aTimeBuf.data(),
-                                 aTimeBuf.size());
-        OString aM(aTimeBuf.data(), aTimeBuf.size() - 1);
-        if (aM.startsWith("D:") && aM.getLength() >= 16)
-        {
-            rInformation.stDateTime.Year = aM.copy(2, 4).toInt32();
-            rInformation.stDateTime.Month = aM.copy(6, 2).toInt32();
-            rInformation.stDateTime.Day = aM.copy(8, 2).toInt32();
-            rInformation.stDateTime.Hours = aM.copy(10, 2).toInt32();
-            rInformation.stDateTime.Minutes = aM.copy(12, 2).toInt32();
-            rInformation.stDateTime.Seconds = aM.copy(14, 2).toInt32();
-        }
-    }
+    rInformation.stDateTime = rSignature.m_pSignature->getTime();
 
     // Detect if the byte ranges don't cover everything, but the signature itself.
     if (rSignature.m_aByteRanges.size() < 2)


More information about the Libreoffice-commits mailing list