summaryrefslogtreecommitdiff
path: root/xmlsecurity/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-11-09 16:32:48 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-11-09 19:21:59 +0000
commitf68b1541ea2f26a1137d4d20ceb23d036d0a00b7 (patch)
tree17d63b485284fb27403a31cf9a709412a53d6826 /xmlsecurity/source
parent2a7e39eac2f44ad48455c8a5c04242b1fc92c726 (diff)
xmlsecurity PDF sign: improve suggested signature ID
So that when we have a single signature with ID="Signature2", then we use "Signature3" for the next ID, not "Signature2". (Acrobat uses that ID for the first signature.) Change-Id: I7032fbf014184da2a5be24730a92abc32a9a1258 Reviewed-on: https://gerrit.libreoffice.org/30725 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r--xmlsecurity/source/pdfio/pdfdocument.cxx23
1 files changed, 21 insertions, 2 deletions
diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx
index 8bd942f8dc27..fa0d9cc99a4a 100644
--- a/xmlsecurity/source/pdfio/pdfdocument.cxx
+++ b/xmlsecurity/source/pdfio/pdfdocument.cxx
@@ -335,11 +335,30 @@ bool PDFDocument::RemoveSignature(size_t nPosition)
return m_aEditBuffer.good();
}
+sal_uInt32 PDFDocument::GetNextSignature()
+{
+ sal_uInt32 nRet = 0;
+ for (const auto& pSignature : GetSignatureWidgets())
+ {
+ auto pT = dynamic_cast<PDFLiteralStringElement*>(pSignature->Lookup("T"));
+ if (!pT)
+ continue;
+
+ const OString& rValue = pT->GetValue();
+ const OString aPrefix = "Signature";
+ if (!rValue.startsWith(aPrefix))
+ continue;
+
+ nRet = std::max(nRet, rValue.copy(aPrefix.getLength()).toUInt32());
+ }
+
+ return nRet + 1;
+}
+
bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate, const OUString& rDescription)
{
// Decide what identifier to use for the new signature.
- std::vector<PDFObjectElement*> aSignatures = GetSignatureWidgets();
- sal_uInt32 nNextSignature = aSignatures.size() + 1;
+ sal_uInt32 nNextSignature = GetNextSignature();
m_aEditBuffer.Seek(STREAM_SEEK_TO_END);
m_aEditBuffer.WriteCharPtr("\n");