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@collabora.com>
This commit is contained in:
Miklos Vajna 2020-11-25 21:08:32 +01:00
parent 586bd08fa2
commit 7ca0f29249
3 changed files with 47 additions and 27 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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)